For Loop executes a subdiagram a set number of
times. Figure 1 shows a For Loop in
LabVIEW, a flow chart equivalent of the For Loop
functionality, and a pseudo code example of the functionality of
the For Loop.
![]() Figure 1 |
The For Loop is located on the
Functions>>All Functions>>Structures palette. You also
can place a While Loop on the block diagram,
right-click the border of the While Loop, and
select Replace with For Loop from the shortcut menu
to change a While Loop to a For
Loop. The value in the count terminal (an
input terminal), shown in 2, indicates how
many times to repeat the subdiagram.
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.
For Loop differs from the While
Loop in that the For Loop executes a set
number of times. A While Loop stops executing the
subdiagram only if the value at the conditional terminal exists.
For Loop in Figure 2 generates a
random number every second for ![]() Figure 2 |
The Wait Until Next ms Multiple function, shown
in 5, monitors a millisecond counter and
waits until the millisecond counter reaches a multiple of the
amount you specify. Use this function to synchronize
activities. Place this function within a loop to control the
loop execution rate.
The Wait (ms) function, shown in 6, adds the wait time to the code execution
time. This can cause a problem if code execution time is
variable.
Time Delay Express VI, located on the
Functions>>Execution Control palette, behaves
similar to the Wait (ms) function with the
addition of built-in error clusters. Refer to Clusters for more information about error
clusters.
For Loop count terminal is a
32-bit signed integer. If you wire a double-precision,
floating-point numeric to the count terminal, LabVIEW converts
the numeric to a 32-bit signed integer. A coercion dot appears
on the count terminal of the first For Loop, as
shown in Figure 3.
![]() Figure 3 |
Divide
function. The 32-bit signed integer is coerced since it uses
fewer bits than the double-precision, floating-point numeric
value.
![]() Figure 4 |
Representation from the
shortcut menu. Select the data type that best represents the
data.ut data types.
x.5 to the nearest even integer. For
example, LabVIEW rounds Comments, questions, feedback, criticisms?
"A full introductory course on programming with LabVIEW."