Skip to content Skip to navigation

OpenStax_CNX

You are here: Home » Content » For Loops

Navigation

Lenses

What is a lens?

Definition of a lens

Lenses

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

What is in a lens?

Lens makers point to 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 member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

This content is ...

Affiliated with (What does "Affiliated with" mean?)

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.
  • NSF Partnership display tagshide tags

    This module is included inLens: NSF Partnership in Signal Processing
    By: Sidney BurrusAs a part of collection: "LabVIEW Graphical Programming Course"

    Click the "NSF Partnership" link to see all content affiliated with them.

    Click the tag icon tag icon to display tags associated with this content.

  • National Instruments display tagshide tags

    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.

    Click the tag icon tag icon to display tags associated with this content.

Also in these lenses

  • Lens for Engineering

    This module is included inLens: Lens for Engineering
    By: Sidney Burrus

    Click the "Lens for Engineering" link to see all content selected in this lens.

  • eScience, eResearch and Computational Problem Solving

    This module is included inLens: eScience, eResearch and Computational Problem Solving
    By: Jan E. OdegardAs a part of collection: "LabVIEW Graphical Programming Course"

    Click the "eScience, eResearch and Computational Problem Solving" link to see all content selected in this lens.

Recently Viewed

This feature requires Javascript to be enabled.

Tags

(What is a tag?)

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

For Loops

Module by: National Instruments. E-mail the author

A For Loop executes a subdiagram a set number of times. Figure 1 shows a For Loop in LabVIEW, a flow chart equivalent of the For Loop functionality, and a pseudo code example of the functionality of the For Loop.

Figure 1
Figure 1 (ForLoopTheory.png)

count.png The For Loop is located on the Functions>>All Functions>>Structures palette. You also can place a While Loop on the block diagram, right-click the border of the While Loop, and select Replace with For Loop from the shortcut menu to change a While Loop to a For Loop. The value in the count terminal (an input terminal), shown in Media 2, indicates how many times to repeat the subdiagram.

iteration.png The iteration terminal (an output terminal), shown in Media 3, contains the number of completed iterations. The iteration count always starts at zero. During the first iteration, the iteration terminal returns 0.

The For Loop differs from the While Loop in that the For Loop executes a set number of times. A While Loop stops executing the subdiagram only if the value at the conditional terminal exists.

The For Loop in Figure 2 generates a random number every second for 100100 seconds and displays the random numbers in a numeric indicator.

Figure 2
Figure 2 (forloopex.png)

Wait Functions

waitms.png The Wait Until Next ms Multiple function, shown in Media 5, monitors a millisecond counter and waits until the millisecond counter reaches a multiple of the amount you specify. Use this function to synchronize activities. Place this function within a loop to control the loop execution rate.

wait.png The Wait (ms) function, shown in Media 6, adds the wait time to the code execution time. This can cause a problem if code execution time is variable.

Note:

The Time Delay Express VI, located on the Functions>>Execution Control palette, behaves similar to the Wait (ms) function with the addition of built-in error clusters. Refer to Clusters for more information about error clusters.

Wait Functions

LabVIEW can represent numeric data types as signed or unsigned integers (8-bit, 16-bit, or 32-bit), floating-point numeric values (single-, double-, or extended-precision), or complex numeric values (single-, double-, or extended-precision). When you wire two or more numeric inputs of different representations to a function, the function usually returns output in the larger or wider format. The functions coerce the smaller representations to the widest representation before execution, and LabVIEW places a coercion dot on the terminal where the conversion takes place.

For example, the For Loop count terminal is a 32-bit signed integer. If you wire a double-precision, floating-point numeric to the count terminal, LabVIEW converts the numeric to a 32-bit signed integer. A coercion dot appears on the count terminal of the first For Loop, as shown in Figure 3.

Figure 3
Figure 3 (coercion.png)

If you wire two different numeric data types to a numeric function that expects the inputs to be the same data type, LabVIEW converts one of the terminals to the same representation as the other terminal. LabVIEW chooses the representation that uses more bits. If the number of bits is the same, LabVIEW chooses unsigned over signed.

In the example in Figure 4, a 32-bit signed integer (I32) and a double-precision, floating-point numeric value (DBL) are wired to the Divide function. The 32-bit signed integer is coerced since it uses fewer bits than the double-precision, floating-point numeric value.

Figure 4
Figure 4 (funcconvert.png)

To change the representation of a numeric object, right-click the object and select Representation from the shortcut menu. Select the data type that best represents the data.ut data types.

When LabVIEW converts double-precision, floating-point numeric values to integers, it rounds to the nearest integer. LabVIEW rounds x.5 to the nearest even integer. For example, LabVIEW rounds 2.52.5 to 22 and 3.53.5 to 44.

Refer to the Data Types section of Introduction to LabVIEW, of this manual or to the LabVIEW Help for more information about data types.

Content actions

Download module as:

Add module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

Definition of a lens

Lenses

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

What is in a lens?

Lens makers point to 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 member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks