2. Session Objective
Concept of Loops in programing
Array building and Array operations
Programming practices using Loop structures.
3. STRUCTURES
Structures control the flow of data in a VI.
LabVIEW has four
structures:
While Loop,
For Loop,
Case structure,
Sequence structure.
4. Repetition and Loops
• Loops and case statements of text- based
programming are represented as structures in G-
programming.
• For Loop
• While Loop
Other examples of structures are
Case structure, Stacked sequence structure
,Flat sequence structure, Event structure ,
Formula node
5. Loops
While Loops
Have Iteration Terminal
Always Run Once
Run According to Continue
Terminal
• For Loops
– Have Iteration Terminal
– Run According to input N count
terminal
6. While Loop
Three different ways of using a while-loop. The first loop continues forever
because the loop conditional never becomes false. The second loop
continues until a button on the front panel is pressed, sending a value of
true to the loop conditional thereby stopping the loop. The third loop also
continues forever, but also displays the current loop counter value in an
indicator on the front panel. (It is important to note that these three loops
will execute in parallel because their inputs are not dependent on each
other)
Iteration
Terminal
Conditional
Terminal
7.
8. Loops (cont.)
1. Select the loop 2. Enclose code to be repeated
3. Drop or drag additional nodes and then wire
9. Use of Structures
Functions>>programming>>structure palette
from here we can select the For loop or While
For Loop can convert in to While Loop by right
clicking on the boundary of the for loop.
10. Loops (cont.)
1. Select the loop 2. Enclose code to be repeated
3. Drop or drag additional nodes and then wire
14. Arrays
Array and its Dimension ,Indexing (0 to n-1)
(Length, height ,depth)
Build arrays manually
Have LabVIEW build arrays automatically
Maximun231 – 1 elements per dimension,
memory permitting.
15.
16. Adding an Array to the Front Panel
From the Controls >> All Controls >> Array and
Cluster subpalette, select the Array Shell
Drop it on the screen.
17. Adding an Array (cont.)
Place data object into shell (i.e. Numeric Control)
18. Creating an Array with a Loop
Loops accumulate arrays at their boundaries