You are here

For Loop

26 July, 2019 - 09:47
Available under Creative Commons-ShareAlike 4.0 International License. Download for free at http://cnx.org/contents/5b6e61df-b830-48cb-9764-94696cb47c80@1.3

This program converts an array of Fahrenheit values to Celsius. Create numeric input and output arrays and label them Fahrenheit and Celsius respectively. In the Fahrenheit array enter the values 0, 20, 40, 60, 80, 100, 120, 140, 160, 180 and 200 at ofsets 0 through 10 as shown in Numeric Input and Output Arrays.

media/image50.png
Figure 1.49 Numeric Input and Output Arrays  

Right click in the Block Diagram window, navigate to Programming » Structures and click on For Loop.

media/image51.png
Figure 1.50 For Loop Structure  

Click and drag to create the For Loop as shown in Creating For Loops and For Loop.

media/image52.png
Figure 1.51 Creating For Loops 
media/image53.png
Figure 1.52 For Loop 

Right click inside the For Loop and select Select a VI... from the pop-up menu. Find the Fahrenheit to Celsius.vi and clickOK. Drop the function inside the For Loop.

media/image54.png
Figure 1.53 Function in Diagram 

To complete the program, wire the Fahrenheit input array to the input terminal of the Fahrenheit

to Celsius function and wire the output terminal of the Fahrenheit to Celsius function to the Celsius output array.

media/image55.png
Figure 1.54 Wired Function in Diagram 

This program uses the For Loop to select each element in the Fahrenheit input array, converts that value to Celsius and saves the results in the Celsius output array. Save the program as Fahrenheit to Celsius For Loop.vi and run the program.

media/image56.png
Figure 1.55 Fahrenheit to Celsius Arrays 

The Celsius output array contains: Celsius {-17.7778, -6.6667, 4.44444, 15.5556, 26.6667, 37.7778, 48.8889, 60, 71.1111, 82.2222, 93.3333}