Specifying Conditions for While Loops

The While Loop contains a subdiagram that executes until the conditional terminal receives a particular Boolean value.

Complete the following steps to specify conditions for a While Loop.

  1. Add a While Loop to the block diagram.

     Add  Find
  2. Add objects inside the While Loop to create a subdiagram that the While Loop repeats.
  3. Wire Boolean data, such as a Boolean control or an output from a Comparison function, to the conditional terminal . You also can right-click the terminal and select Create Constant or Create Control from the shortcut menu to create the Boolean object.
  4. (Optional) By default, the conditional terminal is set to Stop if True. You can change the behavior of the conditional terminal by right-clicking the terminal and selecting Continue if True.
Note  If you do not specify a condition, the While Loop becomes an infinite loop. Changing the value of the control does not stop the infinite loop because the value is only read once, before the loop starts. To stop an infinite loop, you must abort the VI by clicking the Abort Execution button on the toolbar.

Because the VI checks the conditional terminal at the end of each iteration, the While Loop always executes at least one time. The VI does not run if you do not wire the conditional terminal.

You can prevent code execution in the first iteration by placing a Case structure inside the loop.