While Loops: Repeating Operations Until a Condition Occurs

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 or a collection data type to the input tunnel of a While Loop, the While Loop disables auto-indexing by default. You can enable auto-indexing by right-clicking the�tunnel at�the�loop�border and selecting Enable Indexing from�the�shortcut�menu. When auto-indexing is enabled, the While Loop handles one element in the array or collection per loop iteration. If the number of loop iterations is greater than the array or collection size, the While Loop handles all the elements in the array or collection and uses the default value of�the�array�or�collection�element�type for later iterations.�You can enable or disable auto-indexing depending on how you want the While Loop to process the data.