END (Construct)

Purpose

The END (Construct) statement terminates the execution of a construct. The Construct Termination Statements table lists the appropriate statement to end each construct.

Table 30. Construct termination statements
Construct Termination Statement
ASSOCIATE END ASSOCIATE
DO WHILE END DO
FORALL END FORALL
IF END IF
SELECT CASE END SELECT
WHERE END WHERE
Fortran 95

The END FORALL statement terminates FORALL constructs.

End of Fortran 95

Syntax

Read syntax diagramSkip visual syntax diagram>>-+-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-'
 
Notes:
  1. Fortran 2003 Standard
  2. Fortran 95.
  3. Fortran 95.
Fortran 2003 Standard
ASSOCIATE_construct_name
is a name that identifies an ASSOCIATE construct
End of Fortran 2003 Standard
DO_construct_name
is a name that identifies a DO or DO WHILE construct
Fortran 95
FORALL_construct_name
is a name that identifies a FORALL construct
End of Fortran 95
IF_construct_name
is a name that identifies an IF construct
CASE_construct_name
is a name that identifies a SELECT CASE construct
Fortran 95
where_construct_name
is a name that identifies a WHERE construct
End of Fortran 95

Rules

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.

Fortran 95

In Fortran 95, an END IF statement cannot be branched to from outside of the IF construct.

End of Fortran 95

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.

Examples

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.

Related information