SuivantBasNiv. sup.

8.1 Control Structures 

Branches 

The best way to select alternative paths through a program is to use the block-IF structure: this may comprise a single block to be executed when a specified condition is true or several blocks to cover several eventualities. Where the IF-block would only contain one statement it is possible to use an abbreviated form called (for historical reasons) the logical-IF statement.

There is also a computed GO TO statement which can produce a multi-way branch similar to the "case" statements of other languages.

Loops 

Another fundamental requirement is that of repetition. If the number of cycles is known in advance then the DO statement should be used. This also controls a block of statements known as the DO-loop. A CONTINUE statement usually marks the end of a DO-loop.

Fortran has no direct equivalent of the "do while" and "repeat until" forms available in some program languages for loops of an indefinite number of iterations, but they can be constructed using simple GO TO and IF statements.

Other Control Statements 

The STOP statement can be used to terminate execution. Other statements which affect execution sequence are described in other sections: the END statement was covered in section 4.7; procedure calls including the CALL and RETURN statements are described in section 9.

SuivantHautNiv. sup.