インテル® Fortran コンパイラー 19.0 デベロッパー・ガイドおよびリファレンス
Statement: Transfers control from a subprogram to the calling program unit.
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 Standard Fortran.) |
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).
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.
The following shows another example:
SUBROUTINE Loop
CHARACTER in
10 READ (*, '(A)') in
IF (in .EQ. 'Y') RETURN
GOTO 10
! RETURN implied by the following statement:
END
! The following example shows alternate returns:
CALL AltRet (i, *10, *20, *30)
WRITE (*, *) 'normal return'
GOTO 40
10 WRITE (*, *) 'I = 10'
GOTO 40
20 WRITE (*, *) 'I = 20'
GOTO 40
30 WRITE (*, *) 'I = 30'
40 CONTINUE
END
SUBROUTINE AltRet (i, *, *, *)
IF (i .EQ. 10) RETURN 1
IF (i .EQ. 20) RETURN 2
IF (i .EQ. 30) RETURN 3
END
In the above example, RETURN 1 specifies the list's first alternate-return label, which is a symbol for the actual argument *10 in the CALL statement. RETURN 2 specifies the second alternate-return label, and RETURN 3 specifies the third alternate-return label.