HomeModulesModule 1.3 (LabVIEW Loops)Connect
I ntroduce
C onnect
A pply
R eflect
E xtend

Connect - LabView Loops

The While Loop

Definition

A While Loop executes all or a portion of your Block Diagram code multiple times.

A While loop is equivalent to the following pseudo-code:

Do

Execute diagram Inside the loop

While the condition is TRUE/FALSE


How to Create a While Loop

You select the while loop by popping-up in the
Block Diagram > Functions > Structures > While Loop:

You then drag a rectangle area around the portion of Block Diagram code that you want to be included in the while loop:

When you let go of the cursor, you will see the while loop encompassing the code to be included in the while loop:


While Loop Components:

The While Loop

    The While Loop encompasses the Block Diagram code. The loop area is re-sizeable; just select the border and drag. You can also add or remove Block Diagram nodes and elements to and from the while loop by dragging or dropping them inside or outside.

The Conditional Terminal

The conditional terminal has two possible states.

This is the default Continue if True condition. This means that the while loop will continue to repeat the code until a boolean value of FALSE is passed to the conditional terminal.

This is the Stop if True condition. This means that the while loop will continue to repeat the code until a boolean value of TRUE is passed to the conditional terminal. You change the conditional terminal to this condition by popping-up on the terminal and selecting Stop If True from the pop-up menu:

You can switch back to the Continue if True condition by reversing the above procedure:

The Iteration Terminal

The Iteration Terminal is a terminal that outputs the number of times the loop has been executed. The count starts at zero (the first iteration of the loop is Iteration Zero). This is often wired to an indicator terminal to keep track of the number of iterations; it can also be utilized to increment data in the loop.


Controlling a While Loop

Where does the boolean value come from? Generally the conditional terminal is wired to a Boolean Terminal. This terminal represents a Boolean Control (switch) on the Front Panel for the user to control the operation of the while loop.


The For Loop

Definition

The For Loop repeats Block Diagram code a predetermined number of counted times. When the number of iterations equals the predetermined count, the loop stops.

A For Loop is equivalent to the following pseudo-code:

For i = 0 to N-1

Execute diagram inside the loop


How to Create a For Loop

You select the for loop by popping-up in the
Block Diagram > Functions > Structures > For Loop:

 

You then drag a rectangle area around the portion of Block Diagram code that you want to be included in the for loop:

When you let go of the cursor, you will see the for loop outline encompassing the code to be included in the for loop:


For Loop Components:

The For Loop

The for loop itself encompasses the Block Diagram code. The loop area is re-sizeable. Just select the border and drag. You can also add or remove Block Diagram nodes and elements to and from the for loop by dragging or dropping them inside or outside.

The Count Terminal

The Count Terminal is where the predetermined count is placed. Often, a control terminal or a numeric constant is wired to the count terminal to control the number of iterations.

The Iteration Terminal

The Iteration Terminal in a for loop is much like the iteration terminal in a while loop. It is a terminal that outputs the number of times the loop has been executed. The count starts at zero (the first iteration of the loop is Iteration Zero) This is often wired to an indicator terminal to keep track of the number of iterations; as with the while loop above, it can also be utilized to increment data in the loop.

Click here to move on to the next section (Apply).