You are here

For Loop

26 July, 2019 - 09:47
Available under Creative Commons-ShareAlike 4.0 International License. Download for free at

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.

Figure 1.49 Numeric Input and Output Arrays  

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

Figure 1.50 For Loop Structure  

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

Figure 1.51 Creating For Loops 
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 and clickOK. Drop the function inside the For Loop.

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.

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 and run the program.

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}