Auto-Indexing Tunnels with For Loops and While Loops in LabVIEW

Updated Jun 14, 2018

Reported In

Software

  • LabVIEW Full
  • LabVIEW Base
  • LabVIEW Professional

Issue Details

When wiring through a While Loop or For Loop, the tunnels for the wires are either solid or have square brackets on them. What is the difference in these tunnels and how can I change them?

Solution

                          
Auto-indexed tunnel enabled                      Auto-indexed tunnel disabled
 
When you have small brackets inside the tunnels, auto-indexing is enabled. This is the default setting when you wire in or out of For Loops. If you enable auto-indexing on an array wired to a For Loop input terminal, LabVIEW sets the count terminal to the array size so you do not need to wire the count terminal.

Auto-indexing is enabled by default for every array you wire to a For Loop because a common application of a For Loop is to process individual array elements. Disable auto-indexing if you do not need to process the elements of an array individually. When you disable auto-indexing input, the For Loop handles all the elements in the array at once, instead of handling an element per iteration. 

Likewise, when you auto-index an array output tunnel, 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. If you disable auto-indexing in the output tunnel, you receive the value of data from the last iteration, not the elements from every iteration. To change this setting, right-click on the tunnel and select Disable Indexing or Enable Indexing

Auto-Indexing is disabled by default when wiring in or out of While Loops so the wiring tunnel will be solid. If you enable auto-indexing for an array entering a While Loop, the While Loop indexes the array the same way a For Loop does. 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 is met. Additionally, when you auto-index an array output tunnel, the output array receives a new element from every iteration of the loop.
 

Additional Information

  • If two arrays of different lengths are auto-indexed into a For Loop, then the smaller size array determines the total number of iterations. Example: two numeric arrays of sizes 4 and 8 are auto-indexed into a for loop, the total number of iterations will be limited to 4. 
  • If two arrays of different length are auto-indexed into a While Loop, then they will both be indexed until they are out of data and the default value of that data type will pad the rest of the array every subsequent iteration. A while loop has a stop condition that is independent of the arrays, so the program must take care to stop the while loop when appropriate to avoid erroneous data being added to the input and output arrays.

WAS THIS ARTICLE HELPFUL?

Not Helpful