5.7.3 IF Constructs

IF constructs conditionally execute blocks (groups) of statements. An IF construct takes the following form:

[name:] IF (e) THEN
  block
[ELSE IF (e1) THEN
  block] . . .
[ELSE
  block]
END IF [name]
name (Alpha only)
Is the name of the IF construct.
e, e1, e2
Are logical expressions.
block
Is a sequence of zero or more complete Fortran statements (also called a statement block).

Rules and Behavior

On Alpha processors, if a construct name is specified in an IF statement, the same name must appear in the terminal END IF statement. If no construct name is specified in the IF statement, no name can appear in the terminal END IF statement. The same construct name must not be used for different named constructs in the same program unit; it must be unique.

Each statement in an IF construct, except the END IF statement, has an associated statement block. The statement block is conditionally executed based on the values of the logical expressions in the preceding IF construct statement.

The functions of individual statements in an IF construct are as follows:

After the last statement in a statement block is executed, control passes to the next executable statement following the END IF statement. Consequently, no more than one statement block in an IF construct is executed each time the IF THEN statement is executed.

ELSE IF THEN and ELSE statements can have statement labels, but the labels cannot be referenced. The END IF statement can have a statement label to which control can be transferred from anywhere within the IF construct.

Figure 5-4 shows the flow of control for four examples of IF constructs.

Figure 5-4 Examples of IF Constructs


Previous Page Next Page Table of Contents