Table Of Contents

For Loop (G Dataflow)

Last Modified: January 9, 2017

Executes its subdiagram n times. The iteration terminal provides the current loop iteration count, which ranges from 0 to n-1.

Programming Patterns
terminal_icon

Iteration

Current loop iteration count. The loop count always starts at zero for the first iteration. The maximum number of iterations is 2,147,483,647, or 231-1.

If you need to keep count of more than 2,147,483,647 iterations, you can use shift registers with a greater integer range.

terminal_icon

Count

Number of times to execute the code inside the For Loop. If you wire 0 or a negative number to the count terminal, the loop does not execute.

This terminal also returns the loop count.

terminal_icon

Tunnel

Point through which data enters or exits a structure.

In addition to this basic purpose, tunnels can assume the following types of functionality:

  • Non-indexing tunnel—Passes the data through the loop border.
  • Auto-indexing The behavior of an auto-indexing tunnel depends on whether it is an input or output tunnel. An auto-indexing input tunnel processes one element of an array for each iteration of the loop. An auto-indexing output tunnel appends a piece of data from a single loop iteration to an accumulating array of data. To turn on auto-indexing for a tunnel, right-click the tunnel and select Auto Index Values.
terminal_icon

Shift Register

Member of a pair of terminals that passes a value from one iteration of a loop to the next iteration. After the initial loop iteration, the left shift register in the pair returns the value it receives from the right shift register from the previous iteration.

Refer to Accessing Data from the Previous Loop Iteration for more information about passing values from the previous iteration to the current iteration.

Controlling Loop Timing

Refer to Loop Timing for more information about controlling the execution speed of a loop.

Accessing Data from the Previous Loop Iteration

Refer to Accessing Data from the Previous Loop Iteration for more information about passing values from the previous iteration to the current iteration.

Output Tunnel and Shift Register Behavior After Zero Iterations

When you wire data directly through a For Loop that iterates zero times, all indicators wired to output tunnels display the default value for the data type. All indicators wired to output shift registers display the data wired to the input shift register.

How does a For Loop with an auto-indexing input tunnel determine how many times to execute?

By not wiring a value to the count terminal when auto-indexing is enabled, you allow LabVIEW to set the count terminal to the array size, ensuring that the loop iterates once for each element in the array.

Wiring a value to the count terminal while auto-indexing is enabled causes the For Loop to use the smallest of the choices between the count terminal and the input array size to determine the number of loop iterations. For example, if an auto-indexed array enters the loop with 10 elements and you wire a value of 15 to the count terminal, the loop executes 10 times.

A For Loop can process multiple arrays one element at a time using multiple auto-indexing input tunnels. In this situation, the loop uses the smallest array size to determine the number of loop iterations. For example, if two auto-indexed arrays enter the loop with 10 and 20 elements respectively, the loop executes 10 times, processing all elements of the first array but only the first 10 elements of the second array.

Where This Node Can Run:

Desktop OS: Windows

FPGA: All devices (only within an Optimized FPGA VI)


Recently Viewed Topics