FORTRAN 77 Language Reference


A RETURN statement returns control to the calling program unit.





Expression of type INTEGER or REAL


Execution of a RETURN statement terminates the reference of a function or subroutine.

Execution of an END statement in a function or a subroutine is equivalent to the execution of a RETURN statement. @

The expression e is evaluated and converted to integer, if required. e defines the ordinal number of the alternate return label to be used. Alternate return labels are specified as asterisks (or ampersands) @ in the SUBROUTINE statement.

If e is not specified, or the value of e is less than one or greater than the number of asterisks or ampersands in the SUBROUTINE statement that contains the RETURN statement, control is returned normally to the statement following the CALL statement that invoked the subroutine.

If the value of e is between one and the number of asterisks (or ampersands) in the SUBROUTINE statement, control is returned to the statement identified by the eth alternate. A RETURN statement can appear only in a function subprogram or subroutine.


Example 1: Standard return:

       TEXT = "Some kind of minor catastrophe"
       CALL OOPS ( TEXT ) 
       CHARACTER S* 32 
       WRITE (*,*) S 

Example 2: Alternate return:

       CALL RANK ( N, *8, *9 ) 
       WRITE (*,*) 'OK - Normal Return' 
8     WRITE (*,*) 'Minor - 1st alternate return' 
9     WRITE (*,*) 'Major - 2nd alternate return' 
       SUBROUTINE RANK (N, *,*) 
       IF ( N .EQ. 0 ) RETURN 
       IF ( N .EQ. 1 ) RETURN 1 
       RETURN 2