The While Loop and Waveform Chart
Condition-Controlled Graphical Iteration
Condition-Controlled Graphical Iteration lets you repeat a graphical program until a Boolean condition tells it to stop. In LabVIEW, you use a While Loop for repetition and a waveform chart to view successive readings. This combination suits a monitoring display whose stopping time depends on an operator or a measured value rather than a predetermined duration.
Complete an iteration, then decide
Condition-controlled iteration means that a Boolean condition determines whether another iteration begins. A LabVIEW While Loop executes its body at least once. Its conditional terminal controls continuation after the current iteration completes; it does not cancel work already belonging to that iteration.
Name the terminal setting before interpreting its Boolean input:
Terminal setting | Input is True | Input is False |
|---|---|---|
Stop if True | Finish this iteration and exit | Begin another iteration |
Continue if True | Begin another iteration | Finish this iteration and exit |
The iteration terminal, i, starts at zero. For ordinary runs within its integer range, the number of completed iterations is therefore
Put repeated operations inside the loop
Place the scalar-value source, waveform-chart terminal, and Stop-button terminal inside the While Loop when each should participate in every iteration. Wire the scalar source to the chart. With one scalar written per iteration, each completed iteration contributes one chart point, including the final iteration.
Keeping the Stop-button terminal inside lets the program read it again on successive iterations. A Boolean control read outside the loop and passed through an ordinary input tunnel supplies the value read before loop execution; pressing that button later does not refresh the tunnel value. Similarly, a chart connected outside through an ordinary output tunnel receives its data when the loop finishes, rather than once per iteration.
For threshold stopping, compare the current scalar with the limit. Under Stop if True, a condition such as P≥Plimit stops after an iteration whose reading meets the limit. You can combine that comparison with the Stop button using Boolean OR.
Separate timing from axis labels
A Wait (ms) function inside the loop helps pace repetition. Its input is a requested wait, not a measurement of the complete iteration period. Other work and operating-system scheduling can affect the actual interval, so a wait setting alone does not establish exact sample timing.
If successive chart updates really occur at a fixed interval Δt, their rate and relative times are
For example, updates separated by 0.250 s occur at 4.00 Hz. With the first point at t0=0, point i=4 represents 1.00 s.
Scalar chart input does not itself provide timestamps. For a relative-time display, use an x-axis offset of zero and a multiplier equal to the known interval in seconds. Changing that multiplier changes the labels, not the loop's execution speed. If timing varies substantially, equally spaced labels should not be treated as measured timestamps.
Interpret the retained history
Chart history is the collection of previous values retained by the waveform chart. For scalar input, a history length H limits the retained points per plot; after it fills, newer points replace the oldest retained values. The visible axis range and the history capacity are different settings.
For H retained points with uniform spacing, the oldest-to-newest time span is
Nine retained points spaced by 0.250 s span 8(0.250)=2.00 s. There are eight gaps between nine points.
What to remember
- A While Loop completes at least one iteration; identify its terminal setting.
- Keep operations inside the loop when they should repeat.
- Use known update timing to interpret chart time labels.
- A full history of H uniformly spaced points spans (H−1)Δt.
Example: Monitor a simulated pressure rise
A LabVIEW test panel uses Condition-Controlled Graphical Iteration to display a simulated pressure rise. On iteration i, the source produces
The source and waveform-chart terminal are inside a While Loop, with exactly one scalar written per iteration. The first reading occurs at t0=0, and subsequent readings occur at exactly 0.200 s intervals. Treat these intervals as given timing measurements, not as consequences of a Wait setting.
The chart history is initially empty and has capacity H=4 scalar points. The loop should stop when the current pressure reaches or exceeds 105.5 kPa or the operator presses Stop. The Stop button remains False throughout this run.
a) Specify the stopping configuration and determine the final iteration index and total chart updates.
Select Stop if True. Place the Stop-button terminal inside the loop so it is read repeatedly. Compare the current pressure with the threshold, combine that result with Stop using Boolean OR, and wire the result to the conditional terminal:
Because Stop remains False, solve for the first integer index that satisfies the pressure condition:
Check the readings on either side of the stopping boundary:
Iteration i=5 meets the threshold. It still writes its pressure to the chart before the loop exits. The completed iterations have indices 0 through 5, so
The final index is 5, and the chart receives 6 updates.
b) Find the update rate and the time of the final pressure reading.
The specified interval between successive readings is Δt=0.200 s. Its reciprocal gives the update rate:
The first reading is at zero, so the reading at index 5 occurs after ________ intervals:
The update rate is 5.00 Hz, and the final reading occurs at 1.00 s. Six readings contain five first-to-last intervals; multiplying the reading count by the interval would incorrectly place the final reading one interval late. The time found here is the reading time, not a separate measurement of when every remaining loop operation finishes.
c) Identify the readings retained when the loop stops and calculate their oldest-to-newest time span.
The loop produces ________ points, but the history retains only the latest four. The first retained index is therefore
Calculate each retained time using ti=i(0.200 s) and each pressure using Pi=98.0 kPa+(1.50 kPa)i:
- Index 2: t2=2(0.200 s)=0.400 s and P2=98.0 kPa+(1.50 kPa)(2)=101.0 kPa.
- Index 3: t3=3(0.200 s)=0.600 s and P3=98.0 kPa+(1.50 kPa)(3)=102.5 kPa.
- Index 4: t4=4(0.200 s)=0.800 s and P4=98.0 kPa+(1.50 kPa)(4)=104.0 kPa.
- Index 5: t5=5(0.200 s)=1.000 s and P5=98.0 kPa+(1.50 kPa)(5)=105.5 kPa.
The oldest-to-newest span follows either by subtracting the endpoint times or by counting the ________ gaps between four points:
The retained indices are 2 through 5, and their time span is 0.600 s. The two earliest readings have been displaced from the chart history.
A LabVIEW While Loop sends successive temperature readings to a waveform chart. The chart's update mode determines how incoming points redraw its display. Match each mode to its behavior after the plotting area fills.
Adds new points at the right edge while shifting earlier points to the left.
Erases the displayed trace at the right boundary and begins drawing again from the left.
Returns to the left without erasing the entire trace, using a moving vertical line to separate new and old data.
Scope chart
Sweep chart
Strip chart
A simulated source inside a LabVIEW While Loop would return 2.6, 3.1, 3.7, and 4.2 V on successive calls. The loop calls the source once per iteration and writes that value once to an initially empty waveform chart. Its conditional terminal is set to Continue if True and receives the result of V<3.5 V.
How many updates occur, what is the final iteration index, and what is the last plotted value?