# 7.9 RETURN Statement

The RETURN statement transfers control from a subprogram to the calling program unit.

The RETURN statement takes the following form:

  RETURN [expr]
  expr
  Is a scalar expression that is converted to an integer value if necessary.

  The expr is only allowed in subroutines; it indicates an alternate return. (An alternate return is an obsolescent feature in Fortran 95 and Fortran 90.)

Rules and Behavior

When a RETURN statement is executed in a function subprogram, control is transferred to the referencing statement in the calling program unit.

When a RETURN statement is executed in a subroutine subprogram, control is transferred to the first executable statement following the CALL statement that invoked the subroutine, or to the alternate return (if one is specified).

Examples

The following shows how alternate returns can be used in a subroutine:

       CALL CHECK(A, B, *10, *20, C)
       ...
    10 ...
    20 ...
       SUBROUTINE CHECK(X, Y, *, *, C)
       ...
    50   IF (X) 60, 70, 80
    60   RETURN
    70   RETURN 1
    80   RETURN 2
       END

The value of X determines the return, as follows:

- If X < 0, a normal return occurs and control is transferred to the first executable statement following CALL CHECK in the calling program.
- If X = = 0, the first alternate return (RETURN 1) occurs and control is transferred to the statement identified with label 10.
- If X > 0, the second alternate return (RETURN 2) occurs and control is transferred to the statement identified with label 20.

Note that an asterisk (*) specifies the alternate return. An ampersand (&) can also specify an alternate return in a CALL statement, but not in a subroutine's dummy argument list.

For More Information:

- On the CALL statement, see Section 7.2.
- On obsolescent features in Fortran 95 and Fortran 90, see Appendix A.

Previous Page Next Page Table of Contents