<< Chapter < Page | Chapter >> Page > |
A
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.
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
.
The
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 blockdiagram you want to repeat. When you release the mouse button, a
While Loop
boundary encloses the section you
selected.
Add block diagram objects to the
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 specificBoolean value. The default behavior and appearance of the
conditional terminal is
Stop If True
, shown in
. 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
, contains the number of completed
iterations. The iteration count always starts at zero. Duringthe first iteration, the iteration terminal returns
0
.
In the block diagram in
, the
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
.
In the previous example , there is an increased probability of an infinite loop. Generally, thedesired behavior is to have one condition met to stop the loop, rather than requiring both conditions to be met.
You can
change the behavior and appearance of the conditional terminalby 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 aconditional terminal is
Continue if True
, the
While Loop
executes its subdiagram until the
conditional terminal receives a
False
value, as
shown in
.
The
While Loop
executes until the subVI output is
less than
10.00
or the
Enable
control
is
False
.
Data can be passed out of or into a
While Loop
through a tunnel. Tunnels feed data into and out of
structures. The tunnel appears as a solid block on the borderof the
While Loop
. The block is the color of the
data type wired to the tunnel. Data pass out of a loop afterthe loop terminates. When a tunnel passes data into a loop,
the loop executes only after data arrive at the tunnel.
In
, the
iteration
terminal
is connected to a tunnel. The value in the tunnel does not getpassed to the
Iteration Number
indicator until
the
While Loop
has finished execution.
Only the last value of the iteration terminal displays in the
Iteration Number
indicator.
Notification Switch
Would you like to follow the 'Labview graphical programming' conversation and receive update notifications?