The END (Construct) statement terminates the execution of a construct. The Construct Termination Statements table lists the appropriate statement to end each construct.
Construct | Termination Statement |
ASSOCIATE | END ASSOCIATE |
DO WHILE | END DO |
FORALL | END FORALL |
IF | END IF |
SELECT CASE | END SELECT |
WHERE | END WHERE |
The END FORALL statement terminates FORALL constructs.
>>-+-END ASSOCIATE--+-------------------------------+-+-------->< | | (1) | | | '-ASSOCIATE_construct_name------' | +-END DO--+-------------------+--------------------+ | '-DO_construct_name-' | | (2) | +-END FORALL--+-----------------------+------------+ | '-FORALL_construct_name-' | +-END IF--+-------------------+--------------------+ | '-IF_construct_name-' | +-END SELECT--+-+---------------------+--------+---+ | | '-CASE_construct_name-' | | | '-+----------------------------+-' | | '-SELECT_TYPE_construct_name-' | | (3) | '-END WHERE--+----------------------+--------------' '-where_construct_name-'
If you label the END DO statement, you can use it as the terminal statement of a labeled or unlabeled DO or DO WHILE construct. An END DO statement terminates the innermost DO or DO WHILE construct only. If a DO or DO WHILE statement does not specify a statement label, the terminal statement of the DO or DO WHILE construct must be an END DO statement.
You can branch to an END ASSOCIATE, END DO, END IF, or END SELECT statement from within the ASSOCIATE, DO (or DO WHILE), IF, or CASE construct, respectively. An END IF statement can also be branched to from outside of the IF construct.
In Fortran 95, an END IF statement cannot be branched to from outside of the IF construct.
If you specify a construct name on the statement that begins the construct, the END statement that terminates the construct must have the same construct name. Conversely, if you do not specify a construct name on the statement that begins the construct, you must not specify a construct name on the END statement.
An END WHERE statement must not be a branch target statement.
INTEGER X(100,100) DECR: DO WHILE (I.GT.0)
·
·
·
IF (J.LT.K) THEN
·
·
·
END IF ! Cannot reference a construct name I=I-1 END DO DECR ! Reference to construct name DECR mandatory END
The following example shows an invalid use of the where_construct_name:
BW: WHERE (A /= 0) B = B + 1 END WHERE EW ! The where_construct_name on the END WHERE statement ! does not match the where_construct_name on the WHERE ! statement.