STOP statement

Standard: F77 F90 F95 F2003 F2008 F2018 Example program


STOP [ expression ] [ , QUIET = logical-expression ]

Before Fortran 2008, the expression was required to be an unsigned integer literal constant with at most five digits, or a scalar character literal of default kind. In Fortran 2008, the expression is permitted to be any scalar constant expression of type Integer or Character, in both cases the kind must be the default kind. Fortran 2018 further permits the expression to be non-constant.

The logical-expression must be scalar.


The STOP statement initiates normal program termination. Any files that are open will be closed properly (unlike error termination). Execution of the END statement of the main program will also cause normal termination.

In a coarray program with multiple images, normal termination only stops the executing image; the remaining images continue to execute, and continue to have access to coarray data on the stopped image. The whole program only finishes execution when every image has normally terminated.

Normal termination, whether by a STOP statement or otherwise, will display an informative message on the ERROR_UNIT if any IEEE exception is signalling at that time, unless QUIET= appears and the logical-expression has the value .TRUE.; QUIET=.TRUE. also suppresses display of the “stop code” (expression).

The remaining details apply to the NAG Fortran Compiler (they are not guaranteed by the Fortran standard).

If expression appears and QUIET=.TRUE. does not appear, the value of the expression is displayed on the standard error unit, prefixed with “STOP: ”. An integer value is displayed in decimal (I0 format) and a character value is displayed without quotes (A format). No message is displayed if there is no expression.

If expression appears and is of type integer, the lower eight bits of its value are returned as the process exit status; otherwise, the process exit status is zero.


END statement, END PROGRAM statement, ERROR STOP statement, PAUSE statement