1.4 Flow of Control

In the programs we have seen so far, the statements in the program have been run sequentially, one after the other. This is the default behavior. The flow of execution of a program can also be controlled by a programmer. One simple way to change a program's flow of control is to organize a sequence of one or more steps into a group or block that works a single unit. The block of statements is executed several times, each time performing slightly different computation. We see examples of such control of program flow in this section.

We want to write a program that converts temperatures given in Fahrenheit to Celsius using the standard
formula . Here, F is a temperature specified in the Fahrenheit scale, and C is the equivalent temperature in the Celsius scale. The program starts with 0(sup>o Fahrenheit and goes up to 300o Fahrenheit with a step size of 20o. For each Fahrenheit temperature, it prints the corresponding Celsius temperature. Each temperature pair is printed in a line. The output of the program is given below.

   0  -17.8
  20   -6.7
  40    4.4
  60   15.6
  80   26.7
 100   37.8
 120   48.9
 140   60.0
 160   71.1
 180   82.2
 200   93.3
 220  104.4
 240  115.6
 260  126.7
 280  137.8
 300  148.9

Here, the first column represents a Fahrenheit temperature, and the second column represents the Celsius equivalent.