Connexions

You are here: Home » Content » While Loops
Content Actions
Lenses

What is a lens?

Lenses

A lens is a custom view of Connexions content. You can think of it as a fancy kind of list that will let you see Connexions through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to Connexions materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual Connexions member, a community, or a respected organization.

This content is ...
Affiliated with (?)
This content is either by members of the organizations listed or about topics related to the organizations listed. Click each link to see a list of all content affiliated with the organization.
  • This module is included in aLens by: National InstrumentsAs a part of collection:"LabVIEW Graphical Programming Course"

    Comments:

    "A full introductory course on programming with LabVIEW."

    Click the "National Instruments" link to see all content affiliated with them.

    National Instruments
Also in these lenses
  • This module is included inLens: Connexions Books Available for Print on Demand
    By: ConnexionsAs a part of collection:"LabVIEW Graphical Programming Course"

    Comments:

    "This book is available through the Connexions beta version of print-on-demand from online materials."

    Click the "Printable Books" link to see all content selected in this lens.

    Printable Books
Tags

(?)

These tags come from the endorsement, affiliation, and other lenses that include this content.

While Loops

Module by: National Instruments

A While Loop executes a subdiagram until a condition is met. The While Loop is similar to a Do Loop or a Repeat-Until Loop in text-based programming. Figure 1 shows a While Loop in LabVIEW, a flow chart equivalent of the While Loop functionality, and a pseudo code example of the functionality of the While Loop.
WhileLooptheory.png
Figure 1
The While Loop is located on the Functions>>Execution Control palette. Select the While Loop from the palette then use the cursor to drag a selection rectangle around the section of the block diagram you want to repeat. When you release the mouse button, a While Loop boundary encloses the section you selected.
Add block diagram objects to the While Loop by dragging and dropping them inside the While Loop.
Note: The While Loop always executes at least once.
stopiftrue.png The While Loop executes the subdiagram until the conditional terminal, an input terminal, receives a specific Boolean value. The default behavior and appearance of the conditional terminal is Stop If True, shown in 2. When a conditional terminal is Stop If True, the While Loop executes its subdiagram until the conditional terminal receives a True value.
iteration.png The iteration terminal, an output terminal, shown in 3, contains the number of completed iterations. The iteration count always starts at zero. During the first iteration, the iteration terminal returns 0.
In the block diagram in Figure 2, the While Loop executes until the subVI output is greater than or equal to 10.00 and the Enable control is True. The And function returns True only if both inputs are True. Otherwise, it returns False.
stoptrueex.png
Figure 2
In the previous example, there is an increased probability of an infinite loop. Generally, the desired behavior is to have one condition met to stop the loop, rather than requiring both conditions to be met.
continueiftrue.png You can change the behavior and appearance of the conditional terminal by right-clicking the terminal or the border of the While Loop and selecting Continue if True, shown at left. You also can use the Operating tool to click the conditional terminal to change the condition. When a conditional terminal is Continue if True, the While Loop executes its subdiagram until the conditional terminal receives a False value, as shown in Figure 3.
conttrueex.png
Figure 3
The While Loop executes until the subVI output is less than 10.00 or the Enable control is False.

Structure Tunnels

Data can be passed out of or into a While Loop through a tunnel. Tunnels feed data into and out of structures. The tunnel appears as a solid block on the border of the While Loop. The block is the color of the data type wired to the tunnel. Data pass out of a loop after the loop terminates. When a tunnel passes data into a loop, the loop executes only after data arrive at the tunnel.
In Figure 4, the iteration terminal is connected to a tunnel. The value in the tunnel does not get passed to the Iteration Number indicator until the While Loop has finished execution.
tunnelex.png
Figure 4
Only the last value of the iteration terminal displays in the Iteration Number indicator.

Comments, questions, feedback, criticisms?

Discussion forum

Send feedback