next up previous contents
Next: Data Objects Up: Language Elements Previous: Comments

 

Statement Ordering

Fortran has some quite strict rules about the order of statements. Basically in any program or procedure the following rules must be used:

  1. The program heading statement must come first, (PROGRAM, FUNCTION or SUBROUTINE). A PROGRAM statement is optional but its use is recommended.
  2. All the specification statements must precede the first executable statement. Even though DATA statements may be placed with executable text it is far clearer if they lie in the declaration area. It is also a good idea to group FORMAT statements together for clarity's sakes.
  3. The executable statements must follow in the order required by the logic of the program.
  4. The program or procedure must terminate with an END statement.

Within the set of specification statements there is relatively little ordering required, however, in general if one entity is used in the specification of another, it is normally required that it has been previously defined. In other words, named constants (PARAMETER s) must be declared before they can be used as part of the declaration of other objects.

The following table details the prescribed ordering:

tabular2544

Execution of a program begins at the first executable statement of the MAIN PROGRAM, when a procedure is called execution begins with the first executable statement after the invoked entry point. The non-executable statements are conceptually `executed' (!) simultaneously on program initiation, in other words they are referenced once and once only when execution of the main program begins.

There now follows a explanation of the table,

Return to corresponding overview page gif


next up previous contents
Next: Data Objects Up: Language Elements Previous: Comments

©University of Liverpool, 1997
Wed May 28 20:20:27 BST 1997
Not for commercial use.