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 1. Construct termination statements
Construct Termination Statement
ASSOCIATE  1  END ASSOCIATE
BLOCK  2  END BLOCK
DO END DO
DO CONCURRENT 2 
DO WHILE
FORALL END FORALL
IF END IF
SELECT CASE END SELECT
SELECT TYPE  1 
WHERE END WHERE
Notes:
  •  1  Fortran 2003
  •  2  Fortran 2008

Syntax

Read syntax diagramSkip visual syntax diagram
>>-END--+-ASSOCIATE--+------------------------------+----+-----><
        |            |                          (1) |    |   
        |            '-ASSOCIATE_construct_name-----'    |   
        +-BLOCK--+--------------------------+------------+   
        |        |                      (2) |            |   
        |        '-BLOCK_construct_name-----'            |   
        +-DO--+-------------------+----------------------+   
        |     '-DO_construct_name-'                      |   
        +-FORALL--+-----------------------+--------------+   
        |         '-FORALL_construct_name-'              |   
        +-IF--+-------------------+----------------------+   
        |     '-IF_construct_name-'                      |   
        |                                            (3) |   
        +-SELECT--+-+---------------------+--------+-----+   
        |         | '-CASE_construct_name-'        |     |   
        |         '-+----------------------------+-'     |   
        |           '-SELECT_TYPE_construct_name-'       |   
        '-WHERE--+----------------------+----------------'   
                 '-where_construct_name-'                    

Notes:
  1. Fortran 2003
  2. Fortran 2008
  3. Fortran 2003
ASSOCIATE_construct_name (Fortran 2003)
A name that identifies an ASSOCIATE construct.
BLOCK_construct_name (Fortran 2008)
A name that identifies a BLOCK construct.
DO_construct_name
A name that identifies a DO, Fortran 2008 beginsDO CONCURRENTFortran 2008 ends, or DO WHILE construct.
FORALL_construct_name
A name that identifies a FORALL construct.
IF_construct_name
A name that identifies an IF construct.
CASE_construct_name
A name that identifies a SELECT CASE construct.
SELECT_TYPE_construct_name (Fortran 2003)
A name that identifies a SELECT TYPE construct.
where_construct_name
A name that identifies a WHERE construct.

Rules

If you label the END DO statement, you can use it as the terminal statement of a labeled or unlabeled DO, Fortran 2008 beginsDO CONCURRENTFortran 2008 ends, or DO WHILE construct. An END DO statement terminates the innermost DO, Fortran 2008 beginsDO CONCURRENTFortran 2008 ends, or DO WHILE construct only. If a DO, Fortran 2008 beginsDO CONCURRENTFortran 2008 ends, 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 from inside or outside of the following constructs to their corresponding END statements.
Table 2. Branch from inside or outside of a construct to its END statement
Construct name Branch from inside Branch from outside Branch target
ASSOCIATE  1    END ASSOCIATE  1 
BLOCK  2  END BLOCK  2 
DO   END DO
DO CONCURRENT 2   
DO WHILE  
IF  3  END IF
CASE   END SELECT
Notes:
  •  1  Fortran 2003
  •  2  Fortran 2008
  •  3  In Fortran 95, you cannot branch from outside of an IF construct to its END IF statement.

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.


Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us