END
Purpose
An END statement indicates the end of a program unit or procedure.
Syntax
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,
END SUBMODULE, or END
PROCEDURE
statement, it must be identical to the name that is specified in the
corresponding BLOCK DATA, FUNCTION,
MODULE, PROGRAM,
SUBROUTINE,
SUBMODULE, or MODULE
PROCEDURE
statement.
For an internal subprogram or module subprogram, you must specify the
FUNCTION or SUBROUTINE keyword on the
END statement.
In 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.
For block data program units, external subprograms, the main program,
modules, interface bodies,
submodules, and separate module subprograms
, the
corresponding keyword is optional.
The END, END FUNCTION,
END PROCEDURE
,
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
