Before you begin this lesson, you should read sections 8.1--8.4 of the text.
The only statement for performing repetition in Fortran 77 is the DO loop. But the DO loop has a big disadvantage: it executes a fixed number of times. Often we want to run a loop, not for a predetermined number of iterations, but until something interesting happens. Try to think of a few examples.
Fortran 90, the successor to Fortran 77, has an additional loop statement that makes it easy to do this kind of thing. Fortunately, the Fortran 77 compiler that we are using supports this statement, so we will use it.
The text shows you how to code more flexible loops using the GOTO statement. The GOTO statement has all but disappeared from modern languages because its undisciplined use can lead to hopelessly obscure programs. Instead, language designers have identified the most common uses for GOTO statements and provided ``structured'' alternatives for their use. As a result, most C and Pascal programmers, for example, never use a GOTO statement.
You will sometimes need to use a GOTO statement in this class. But mark these words. You must not use a GOTO statement except in the way recommended in chapter 8 of the text. Any other uses of GOTO statements are simply not tolerated in polite society.
In this lesson we'll look at two examples of loops that do not run for a fixed number of iterations. You'll find other examples in chapter 8.
You need to copy some files before we begin.
Hamlet Project