Conditionally transfers control or executes a statement or block of statements. For each type of IF statement, the decision to transfer control or to execute the statement or block of statements is based on the evaluation of an expression within the IF statement.
1 – Arithmetic
Conditionally transfers control to one of three statements, based
on the current value of an arithmetic expression. Statement
format:
IF (e) s1,s2,s3
e Is an arithmetic expression.
s1,s2,s3 Are labels of executable statements in the same
program unit. All three labels are required,
but they need not refer to different statements.
Executes the statement at the first label ("s1") if the arithmetic
expression evaluates to a value less than 0; the statement at the
second label ("s2") if the arithmetic expression evaluates to 0; or
the statement at the third label ("s3") if the arithmetic
expression evaluates to a value greater than 0.
NOTE
The arithmetic IF statement is an obsolescent
feature in Fortran 95 and Fortran 90. HP
Fortran fully supports this feature.
2 – Logical
Executes the statement if the logical expression is true. In
Fortran 95/90, this is called an IF statement (as compared to block
IFs, which are called IF constructs). Statement format:
IF (e) st
e Is a logical expression.
st Is a complete Fortran statement. The statement can
be any statement except DO, END DO, END, block IF,
CASE, FORALL, or WHERE constructs, or another logical
IF statement.
3 – Block
Executes a block of statements if the logical expression is true.
The block of statements starts immediately following the IF
statement. The block of statements can be followed by optional
ELSE IF statements (any number) and one optional ELSE statement.
The entire block IF construct must be terminated by an END IF
statement. Format:
[name:] IF (e) THEN
block
[ELSE IF (e1) THEN [name]
block]...
[ELSE [name]
block]
END IF [name]
name Is the name of the IF construct.
e,e1 Are logical expressions.
block Is a series of zero or more Fortran statements
(called a statement block).
If a construct name is specified in a block IF statement, the same
name must appear in the terminal END IF statement. If no construct
name is specified in the block IF statement, no name can appear in
the terminal END IF statement. The construct name must be a unique
identifier in the program unit.
NOTE
No additional statement can be placed after the IF
THEN statement in a block IF construct. For
example, the following statement is invalid in the
block IF construct:
IF (e) THEN I = J
This statement is translated as the following
logical IF statement:
IF (e) THENI = J