Loop auto indexing using LabView : tutorial 9

In this tutorial, you will learn the concept of auto-indexing using loops in LabView. At the start there is a complete general introduction explaining the working and uses of auto-indexing. After that, auto-indexing is explained with the help of a program on LabView. Enabling and disabling of auto-indexing is done. At the end of the tutorial you are provided with an exercise to do it by yourself, and in the next tutorials I will assume that you have done those exercises and I will not explain the concept regarding them.

Introduction to auto indexing in Labview

Using loops in LabView you may have noticed and whenever you place an outgoing wire through a loop, the tunnel is either solid or have square brackets on them. What do these differences in the tunnels represent?When you have small brackets inside the tunnels, auto-indexing is enabled. This setting is unique in all versions of LabView using either for loop or while loop. LabView also sets the count terminal to the array if you enable auto-indexing on an array wired to a For Loop input terminal, so you do not need to wire the count terminal.

Common application of a ‘For’ loop is basically is to process the individual elements of array. Therefore, auto-indexing is enabled by default for every array you wire to a For Loop. If processing array elements in array individually is not required you can also disable auto-indexing. ‘For’ loop handles all the elements in the array at once if you disable auto-indexing input instead of handling an element per iteration.

The output array receives a new element from every iteration of the loop, when you auto-index an array output tunnel. Hence the size and number of iterations of the auto-indexed output array are always equal. Last iteration data will be received if you disable auto-indexing in the output tunnel and not the elements individually. You can also change this setting by clicking right on the tunnel and select Disable Indexing or Enable Indexing.

When working with while loop auto-Indexing is disabled by default, so the wiring tunnel will be solid. The while loop indexes of the array work in the same manner as that of for loop when you enable auto-indexing for an array entering a While Loop. While loop iterates until a specific condition is satisfied, therefore, the number of iterations a While Loop executes is not limited by the size of the array. The output array receives a new element from every iterations when you auto-index an array output tunnel.

Auto indexing program in Labview

  • As an example, consider a ‘for’ loop that generate random numbers in the output. For this purpose create a blank VI and save it as done in previous tutorials.
  • Place a for loop in it from function palette>structures>>for loop as shown belowfor loop auto indexing

Figure 1: for loop

  • Set the number of iterations to 10, by using a constant.
  • From the function palette select numeric and then select random number this will generate random numbers automatically.random number in labview

Figure 2: Random number block

  • Connect the output terminal of the random number generator to the boundary of the ‘for’ loop. It will create a tunnel, see the figure below.Tunnel in labview

Figure 3: Tunnel

  • You can see two square brackets inside the tunnel, and when you hover over the tunnel the pointer will say “Auto-indexed tunnel”, refer to the figure below,Auto-indexed tunnel

Figure 4: Auto indexing tunnel

  • This means that the auto-indexing is enabled. What this means is that the loop will automatically create an array from the scalar values that reach the values inside the loop. Now by right clicking on this tunnel a dropdown will appear, select create from that menu and then select indicator as shown below.Indicator loop indexing

Figure 5: Indicator

  • This will automatically place an array indicator on the tunnel, this is because of the auto-indexing tunnel.Array

Figure 6: Array indicator

  • As we have discussed in introduction portion, the size of this array must be equal to the number of iterations. We have set the number of iterations equal to 10 hence expand the size of the array to 10 elements as shown below.Array expansion labview

Figure 7: Expanded array

  • Now, run the program from run button or by pressing <Ctrl+R> to see the results,Output auto indexing labview

Figure 8: Output

  • As the array was connected to the output of a random generator of range 0-1, therefore, the outputs are randomly generated numbers between 0 and 1.
  • Now if we expand the size of the array beyond 10, those elements will remain undeclared even after running the VI, refer to the figure below,Output 2 auto indexing labview

Figure 9: Output 2

  • We do indeed have an array of 10 elements randomly generated.
  • In a similar manner, auto indexing is also used to loop through an array in addition to generating an array. To see this, we will add another for loop to loop through the already created loop, and on one side of the loop boundary attach the output of the first loop also connect the constant selecting number of iterations for each loop, as shown below.2nd for loop

Figure 10: Insertion of second loop

  • In this VI, will loop through the previously generated array, and add five to each element of the array. In the second loop insert an addition block. Connect one input terminal of the addition block to the terminal already present on the loop boundary and on the second input add a constant and insert a value of 5, see the figure below.Loop after adder

Figure 11: Loop after adder

  • Again take the output of this from the loop boundary this will also place auto-indexed tunnel. The auto indexing tunnel will again have square brackets; again at the output create an indicator. Increase the size of this indicator to 10 as well.
  • Run this code and compare the results of the second array with the first array, see the figure below,Looping through array

Figure 12: Looping through an array output

Compare both arrays element wise. Both have same digits except the number 5. The decimal portion of all elements of both array are same. Second for loop installed, loops through the first array element wise, add five to it, and store it in another array named array 2.

Disabling auto-indexing in labview

The bracket, at the output of the loop boundary, appears because auto-indexing is enabled in for loops by default in LabView. You can also disable auto-indexing. For this purpose right click on the tunnel, a drop down will appear, from that select tunnel mode and then select the one you want your tunnel to act the way, see the figure below.Disenabling auto-indexing

Figure 13: Disenabling auto-indexing

Selecting last value will return the last value of the array only, and we will have no record of any of the elements of the array.


  • Try to work on loop auto-indexing using while loop.

(Hint: In while loop, auto-indexing is not enabled by default in LabView)

<<Previous tutorial                                     Next tutorial>>

Leave a Comment