Stopping For Loops When a Condition Occurs

LabVIEW 2018 Help

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

DOWNLOAD (Windows Only)

LabVIEW 2016 Help
LabVIEW 2017 Help
LabVIEW 2018 Help
LabVIEW 2019 Help
LabVIEW 2020 Help

You can add a conditional terminal to configure a For Loop to stop when a condition occurs. A For Loop with a conditional terminal executes until the condition occurs or until all iterations complete, whichever happens first. For example, if you want a loop to execute a set number of times unless an error occurs, you can use a For Loop with a conditional terminal and wire an error cluster to the conditional terminal.

Complete the following steps to stop a For Loop when a condition occurs.

  1. Add a For Loop to the block diagram.

  2. Right-click the loop border and select Conditional Terminal from the shortcut menu. A conditional terminal appears inside the loop and the count terminal appearance changes from the symbol to the symbol.
  3. Add objects inside the For Loop to create a subdiagram that the For Loop repeats.
  4. Wire Boolean data, such as a Boolean control or an output from a Comparison function, or an error cluster 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.
  5. (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. When the conditional terminal is Continue if True , the loop executes until the terminal receives a FALSE value. You also can use the Operating tool to click the conditional terminal to change the condition.
Note  If you wire the conditional terminal in a For Loop, you cannot predetermine the number of iterations the loop executes. You can determine the number of iterations the loop completes by auto-indexing an output array and checking the number of elements after the loop executes or by wiring an indicator to the loop iteration terminal and checking the count after the loop executes.

The number wired to the count terminal or the number of elements in the auto-indexed input array acts as the maximum number of loop iterations that complete if the condition wired to the conditional terminal never occurs. If you want a loop to iterate until a condition occurs with no maximum number of iterations, use a While Loop instead.


Not Helpful