next up previous contents index
Next: DO-Loops Up: IF-Blocks Previous: Block-IF General Rules

Guidelines

The indentation scheme shown in the examples above is not mandatory but the practice of indenting each block by a few characters relative to the rest of the program is strongly recommended. It makes the structure of the block immediately apparent and reduces the risk of failing to match each IF with an END IF. An indenting scheme is especially useful when IF-blocks are nested within others. For example:

 
      IF(POWER .GT. LIMIT) THEN 
          IF(.NOT. WARNED) THEN 
              CALL SET('WARNING') 
              WARNED = .TRUE. 
          ELSE 
              CALL SET('ALARM') 
          END IF 
      END IF
The limited width of the statement field can be a problem when IF-blocks are nested to a very great depth: but this tends to mean that the program unit is getting too complicated and that it will usually be beneficial to divide it into subroutines. If you accidentally omit an END IF statement the compiler will flag the error but will not know where you forgot to put it. In such cases the compiler may get confused and generate a large number of other error messages.

When an IF-block which is executed frequently contains a large number of ELSE IF statements it will be slightly more efficient to put the most-likely conditions near the top of the list as when they occur the tests lower down in the list will not need to be executed.



Mario Storti
Wed Nov 4 19:32:56 ART 1998