FORTRAN 77 Language Reference

RETURN

A RETURN statement returns control to the calling program unit.

RETURN [e]

Parameter 

Description 

e

Expression of type INTEGER or REAL

Description

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.

Examples

Example 1: Standard return:


       CHARACTER*25 TEXT 
       TEXT = "Some kind of minor catastrophe"
       ... 
       CALL OOPS ( TEXT ) 
       STOP 
       END
       SUBROUTINE OOPS ( S ) 
       CHARACTER S* 32 
       WRITE (*,*) S 
       RETURN 
       END 

Example 2: Alternate return:


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