Lesson 4
Using Loops
Recognize the different components of a LabVIEW loop
structure and apply a For Loop or a While Loop
appropriately
A. Loops Review D. Timing a VI
B. While Loops E. Data Feedback in Loops
C. For Loops F. Plotting Data
1
LESSON 4 Using Loops
A. Loops Review
Recognize loop structures and explain how to use them.
• While Loops—Review
• For Loops—Review
• For Loop/While Loop Comparison
2
A. Loops Review
While Loops—Review
3
A. Loops Review
For Loops—Review
4
A. Loops Review
For Loop/While Loop Comparison
5
LESSON 4 Using Loops
Activity 4-1
While Loops vs. For Loops
Review four scenarios and determine the best type of loop to use for each one.
6
LESSON 4 Using Loops
B. While Loops
Recognize tunnels and explain their purpose on a loop
structure and demonstrate how to use error checking and
error handling inside a loop.
• Tunnels
• Error Checking and Error Handling
7
B. While Loops
Tunnels
8
B. While Loops
Error Checking and Error Handling
Stop the While Loop if an error
occurs.
9
LESSON 4 Using Loops
Exercise 4-1
Pass Data Through Tunnels
Use a While Loop and an iteration terminal and pass data through a tunnel.
10
LESSON 4 Using Loops
Exercise 4-1
Pass Data Through Tunnels
How many times is the Number of Iterations indicator updated? Why?
Why do we include the Increment function?
11
LESSON 4 Using Loops
C. For Loops
Demonstrate how to add a conditional terminal to a For Loop and
describe how numeric conversion occurs on the For Loop count
terminal.
• Conditional Terminal
• Count Terminal Numeric Conversion
12
C. For Loops
Conditional Terminal
13
C. For Loops
Count Terminal Numeric Conversion
14
LESSON 4 Using Loops
D. Timing a VI
Identify scenarios that require loop timing and apply the
appropriate function.
• Reasons to Use Timing
• Wait Functions and Express VIs
15
D. Timing a VI
Why do you need timing in a VI?
16
D. Timing a VI
Wait Functions Inside a Loop
17
D. Timing a VI
Wait Function Timing
18
D. Timing a VI
Elapsed Time Express VI
19
LESSON 4 Using Loops
Demonstration
Wait Chart VI
Compare and contrast using a Wait function and the Elapsed Time
Express VI for software timing.
20
LESSON 4 Using Loops
E. Data Feedback in Loops
Apply shift registers when appropriate and predict the
correct value at different iterations of the loop.
• Introduction to Shift Registers
• Using Shift Registers
• Creating Shift Registers
21
E. Data Feedback in Loops
Introduction to Shift Registers
22
LESSON 4 Using Loops
Multimedia Module
Using Shift Registers
• Shift Registers • Default for Unwired Values
• Initializing Shift Registers • Compound Shift Registers
23
LESSON 4 Using Loops
Demonstration
Creating Shift Registers
Create shift registers and convert existing tunnels to shift registers.
24
LESSON 4 Using Loops
Exercise 4-2
Calculating Average
Temperature
Use a While Loop and shift registers to average data.
25
LESSON 4 Using Loops
Exercise 4-2
Calculating Average
Temperature
You calculated the average of the last 5 temperature readings. How would you
modify the VI to calculate the average of the last 10 temperature readings?
26
LESSON 4 Using Loops
F. Plotting Data
Use data feedback in a loop to plot waveform charts.
• Waveform Chart
• Waveform Chart Properties
27
F. Plotting Data
Waveform Chart
28
F. Plotting Data
Waveform Chart Properties
29
LESSON 4 Using Loops
Exercise 4-3
Temperature Monitor VI—Plot
Multiple Temperatures
Plot multiple data sets on a single waveform chart and customize the chart
view.
30
LESSON 4 Using Loops
Exercise 4-3
Temperature Monitor VI—Plot
Multiple Temperatures
In what ways do the following tools allow the user to interact with the plot?
• Plot Legend
• Graph Palette
• Scale Legend
31
LESSON 4 Using Loops
Activity 4-2
Lesson Review
Refer to the participant guide to answer questions about what you have learned
in this lesson and then discuss the answers as a group.
32
Lesson Review
1. Which structure must run at least one
time?
a. For Loop
b. While Loop
33
Lesson Review
1. Which structure must run at least one
time?
a. For Loop
b. While Loop
34