While Loops: Repeating Operations Until a Condition Occurs

LabVIEW 2018 Help


Edition Date: March 2018
Part Number: 371361R-01
View Product Info

DOWNLOAD (Windows Only)


LabVIEW 2015 Help
LabVIEW 2016 Help
LabVIEW 2017 Help
LabVIEW 2018 Help
LabVIEW 2019 Help

Similar to a Do Loop or a Repeat-Until Loop in text-based programming languages, a While Loop, shown as follows, executes a subdiagram until a condition occurs.

The While Loop executes the subdiagram until the conditional terminal, an input terminal, receives a specific Boolean value. The conditional terminal in a While Loop behaves the same as in a For Loop with a conditional terminal. However, the While Loop does not include a set iteration count and runs infinitely if the condition never occurs.

The iteration terminal, shown as follows, is an output terminal that contains the number of completed iterations.

The iteration count for the While Loop always starts at zero.

Passing Data through While Loops

The While Loop does not pass values from one iteration to the next by default. To access data from the previous iteration and use it in the next iteration, add shift registers to the While Loop. For example, if you want to use the result of a mathematic operation in one iteration as the initial value for a mathematic operation in the next iteration, use shift registers.

When you wire an array to the input tunnel of a While Loop, the While Loop enables auto-indexing by default. When auto-indexing is enabled, the While Loop reads and processes one element in the array per loop iteration, rather than reading and processing the entire array each iteration. You can enable or disable auto-indexing depending on how you want the While Loop to process the data.

WAS THIS ARTICLE HELPFUL?

Not Helpful