END

Purpose

An END statement indicates the end of a program unit or procedure.

Syntax

Read syntax diagramSkip visual syntax diagram
>>-END--+-------------------------------------+----------------><
        +-BLOCK DATA--+-----------------+-----+   
        |             '-BLOCK_DATA_name-'     |   
        +-FUNCTION--+---------------+---------+   
        |           '-FUNCTION_name-'         |   
        +-MODULE--+-------------+-------------+   
        |         '-MODULE_name-'             |   
        |  (1)                                |   
        +-------PROCEDURE--+----------------+-+   
        |                  '-PROCEDURE_name-' |   
        +-PROGRAM--+--------------+-----------+   
        |          '-PROGRAM_name-'           |   
        +-SUBROUTINE--+-----------------+-----+   
        |             '-SUBROUTINE_name-'     |   
        |  (2)                                |   
        '-------SUBMODULE--+----------------+-'   
                           '-SUBMODULE_name-'     

Notes:
  1. Fortran 2008
  2. Fortran 2008

Rules

The END statement is the only required statement in a program unit.

If a name is specified in an END BLOCK DATA, END FUNCTION, END MODULE, END PROGRAM, END SUBROUTINE, Fortran 2008 beginsEND SUBMODULE, or END PROCEDUREFortran 2008 ends statement, it must be identical to the name that is specified in the corresponding BLOCK DATA, FUNCTION, MODULE, PROGRAM, SUBROUTINE, Fortran 2008 beginsSUBMODULE, or MODULE PROCEDUREFortran 2008 ends statement.

For an internal subprogram or module subprogram, you must specify the FUNCTION or SUBROUTINE keyword on the END statement. Fortran 2008 beginsIn Fortran 2008, you can omit the FUNCTION and SUBROUTINE keywords on the END statements for internal and module subprograms. However, you cannot add a function or subroutine name on the END statement when the FUNCTION or SUBROUTINE keyword is omitted.Fortran 2008 ends For block data program units, external subprograms, the main program, modules, interface bodies, Fortran 2008 beginssubmodules, and separate module subprogramsFortran 2008 ends, the corresponding keyword is optional.

The END, END FUNCTION, Fortran 2008 beginsEND PROCEDUREFortran 2008 ends, END PROGRAM, and END SUBROUTINE statements are executable statements that can be branched to. In both fixed source form and Fortran 90 free source form formats, no other statement can follow the END statement on the same line. In fixed source form format, you cannot continue a program unit END statement, nor can a statement whose initial line appears to be a program unit END statement be continued.

The END statement of a main program terminates execution of the program. The END statement of a function or subroutine has the same effect as a RETURN statement. An inline comment can appear on the same line as an END statement. Any comment line appearing after an END statement belongs to the next program unit.

Examples

PROGRAM TEST
  CALL SUB()
  CONTAINS
    SUBROUTINE SUB
        ⋮
    END SUBROUTINE    ! Reference to subroutine name SUB is optional
END PROGRAM TEST

Related information



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