The next program will generate Fahrenheit values and convert them to Celsius until a condition is met to stop the iterations in a While Loop. In the Block Diagram window, select the While Loop structure by clicking on it from the Functions » Programming » Structures menu.
Click and drag to create the While Loop structure.
In the Front Panel window, create two numeric output arrays. Label them Fahrenheit and Celsius.
Re-arrange the diagram as in While Loop Diagram .
From the Functions menu, select Multiply function and a couple of numeric constants. Type in 20.0 and 300.0 for the numeric constants. Select the Fahrenheit to Celsius.vi and drop it inside the While Loop. Re-arrange the diagram to look like Generating Fahrenheit Values
From the Functions » Programming » Comparison menu select the Greater or Equal operator.
Wire the While Loop components as shown in Generating Fahrenheit Values & Stop Condition.
Wire the output of the Multiply operation to theFahrenheit and the output of the Fahrenheit to Celsius function to the Celsius numeric output arrays. The connections between the While Loop and the Fahrenheit andCelsius arrays are broken (see Broken Wires).
To repair the broken connections, roll over the mouse pointer to the Loop Tunnel.
Right click on the Loop Tunnel and select Enable Indexing from the pop-up menu.
This enables values to accumulate and store the results into an array. Repeat for the Celsius array.
Each iteration of the While Loop in this program generates an i ×20 Fahrenheit value and converts it to Celsius. The While Loop stops iterating when the generated Fahrenheit value is greater than or equal to 300. The resulting arrays are stored in the Fahrenheit and Celsius numeric output arrays.
Save the program as Fahrenheit to Celsius While Loop.vi and run it. The program generates the following results:
Fahrenheit {0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 240, 260, 280, 300}
Celsius {-17.7778, -6.6667, 4.44444, 15.5556, 26.6667, 37.7778, 48.8889, 60, 71.1111, 82.2222, 93.3333, 104.444, 115.556, 126.667, 137.778, 148.889}
- 1515 reads