ABSTRACT

The programs of §1 and §2 are examples of straight-line code, in which the executable statements are performed exactly once, in order from first to last. If we think of each Fortran statement as being in control of the processor for the duration of its execution, then the progress of execution from one statement to the next can be regarded as a flow of control through the program. In straight-line programs, the flow of control is strictly from top to bottom. Some useful tasks, such as the hypotenuse calculation of §2, can be performed by straight-

line programs. However, most algorithms require the sequence of statements that are executed to be conditional on the values of input data or the results of intermediate computations. Depending on the result of a test, control might be transferred from one statement to another statement that does not immediately follow the first in the top-to-bottom order of the program listing. This change in the flow of control is called a branch. To see how Fortran provides for testing and branching, we will consider the problem

of finding the roots of the quadratic equation ax2 + bx+ c = 0 by evaluating the formula

x = −b±√b2 − 4ac

2a .