![background image](http://html1.mh-extra.com/html/national-instruments/bridgeview/bridgeview_user-manual_3445534243.webp)
Chapter 11
Loops and Charts
11-4
©
National Instruments Corporation
While Loops
A While Loop is a structure that repeats a section of code until a condition
is met. It is comparable to a Do Loop or a Repeat-Until Loop in traditional
programming language.
The While Loop, shown in the following illustration, is a resizable box you
use to execute the diagram inside it until the Boolean value passed to the
conditional terminal (an input terminal) is FALSE. The VI checks the
conditional terminal at the end of each iteration; therefore, the While Loop
always executes at least once. The iteration terminal is an output numeric
terminal that outputs the number of times the loop has executed. However,
the iteration count always starts at zero, so if the loop runs once, the
iteration terminal outputs 0.
The While Loop is equivalent to the following pseudocode:
Do
Execute Diagram Inside the Loop (which sets the
condition)
While Condition is TRUE
Activity 11-2. Use a While Loop and a Chart
Your objective is to use a While Loop and a chart for acquiring and
displaying data in real time.
You will build a VI that generates random data and displays it on a chart.
A knob control on the front panel adjusts the loop rate between 0 and 2
seconds and a switch stops the VI. You will change the mechanical action
of the switch so you do not have to turn on the switch each time you run
the VI. Use the front panel in the following illustration to get started.
Iteration
Terminal
Conditional
Terminal