|LabVIEW 2015 Help|
|LabVIEW 2016 Help|
|LabVIEW 2017 Help|
|LabVIEW 2018 Help|
|LabVIEW 2019 Help|
If you wire an array to a For Loop or While Loop, you can read and process every element in that array by enabling auto-indexing. When you wire an array from an external node to an input tunnel on the loop border and enable auto-indexing on the input tunnel, elements of that array enter the loop one at a time, starting with the first element.
Complete the following steps to pass elements into an array through a loop:
|Note To avoid default data output values when a loop does not execute, enable auto-indexing every time a For Loop has an output tunnel.|
A bracketed glyph appears on the loop output tunnel to indicate that auto-indexing is enabled.
Complete the following steps to configure the output tunnel of the loop to return the indexed value of an array, the last value of an array, or a concatenated array:
Refer to the following table for more information about each of the output options the tunnel can return.
|Indexing||The output array receives a new element from every iteration of the loop. Therefore, auto-indexed output arrays are always equal in size to the number of iterations. For example, if the loop executes 10 times, the output array has 10 elements.|
|Last value||The output tunnel returns only the element from the last iteration of the loop.|
|Concatenating||LabVIEW appends all inputs in order, forming an output array of the same dimension as the array input wired. The Concatenating tunnel mode concatenates arrays the same as the Build Array function.|
Between the output tunnel and the next node, the thickness of the wire indicates whether the loop is indexing, returning the last value, or concatenating the values. Indexing creates a thicker wire than concatenating because the wire contains an array of higher dimension instead of an array of the same dimension. When the output tunnel returns the last value, the wire is thinner than when indexing or concatenating.
|Note The loop indexes scalar elements from 1D arrays, 1D arrays from 2D arrays, and so on. The opposite occurs at output tunnels. Scalar elements accumulate sequentially into 1D arrays, 1D arrays accumulate into 2D arrays, and so on.|
Refer to the labview\examples\Arrays\Arrays.lvproj for examples of building arrays by disabling auto-indexing.
|Loop Type||Array Configuration||Explanation||Example|
|For Loop||One array wired to input tunnel and an unwired count terminal||If you enable auto-indexing on an array wired to a For Loop input tunnel, LabVIEW uses the array size as the number of times to execute so you do not need to wire the count terminal. LabVIEW enables auto-indexing by default for every array you wire to a For Loop.
|For Loop||Wired count terminal||If you enable auto-indexing for this scenario, the actual number of iterations becomes the smaller of the choices.||For example, if you wire an array with 10 elements to a For Loop and a value of 15 to its count terminal, the loop only executes 10 times.|
|For Loop||Multiple Arrays||Like the scenario above, if you enable auto-indexing for more than one tunnel, the number of iterations becomes the smaller of the array choices.||For example, if two auto-indexed arrays enter the loop, with 10 and 20 elements respectively, and you wire a value of 15 to the count terminal, the loop still only executes 10 times, indexing all elements of the first array but only the first 10 elements of the second array. |
As another example, if you plot data from two sources on one graph and you want to plot the first 100 elements, wire 100 to the count terminal. However, if the smaller data source includes only 50 elements, the loop executes 50 times and indexes only the first 50 elements of each data source. Use the Array Size function to determine the size of arrays.
|While Loop||One wired array||If you enable auto-indexing for an array entering a While Loop, the While Loop indexes the array the same way as a For Loop. However, the number of iterations a While Loop executes is not limited by the size of the array because the While Loop iterates until a specific condition occurs. When a While Loop indexes past the end of the input array, the default value for the array element type passes into the loop.
You can prevent the default value from passing into the While Loop by using the Array Size function. The Array Size function indicates how many elements are in the array. Set up the While Loop to stop executing when the number of iterations equals the array size.
Auto-indexing for While Loops is disabled by default.