While Loop executes a subdiagram until a
condition is met. The While Loop is similar to a
Do Loop or a Repeat-Until Loop in
text-based programming. Figure 1 shows a
While Loop in LabVIEW, a flow chart equivalent of
the While Loop functionality, and a pseudo code
example of the functionality of the While Loop.
![]() Figure 1 |
While Loop is located on the
Functions>>Execution Control palette. Select the
While Loop from the palette then use the cursor to
drag a selection rectangle around the section of the block
diagram you want to repeat. When you release the mouse button, a
While Loop boundary encloses the section you
selected.
While Loop by
dragging and dropping them inside the While Loop.
While Loop always executes at least once.
The
While Loop executes the subdiagram until the
conditional terminal, an input terminal, receives a specific
Boolean value. The default behavior and appearance of the
conditional terminal is Stop If True, shown in
2. When a conditional terminal is Stop
If True, the While Loop executes its
subdiagram until the conditional terminal receives a
True value.
The
iteration terminal, an output terminal, shown in
3, contains the number of completed
iterations. The iteration count always starts at zero. During
the first iteration, the iteration terminal returns
0.
While
Loop executes until the subVI output is greater than or
equal to 10.00 and the Enable control
is True. The And function returns
True only if both inputs are
True. Otherwise, it returns False.
![]() Figure 2 |
You can
change the behavior and appearance of the conditional terminal
by right-clicking the terminal or the border of the While
Loop and selecting Continue if True, shown
at left. You also can use the Operating tool to
click the conditional terminal to change the condition. When a
conditional terminal is Continue if True, the
While Loop executes its subdiagram until the
conditional terminal receives a False value, as
shown in Figure 3.
![]() Figure 3 |
While Loop executes until the subVI output is
less than 10.00 or the Enable control
is False.
While Loop
through a tunnel. Tunnels feed data into and out of
structures. The tunnel appears as a solid block on the border
of the While Loop. The block is the color of the
data type wired to the tunnel. Data pass out of a loop after
the loop terminates. When a tunnel passes data into a loop,
the loop executes only after data arrive at the tunnel.
iteration terminal
is connected to a tunnel. The value in the tunnel does not get
passed to the Iteration Number indicator until
the While Loop has finished execution.
![]() Figure 4 |
Iteration Number indicator.
Comments, questions, feedback, criticisms?
"A full introductory course on programming with LabVIEW."