RETURN Statement (Executable) [ HP FORTRAN 77/iX Reference ] MPE/iX 5.0 Documentation
HP FORTRAN 77/iX Reference
RETURN Statement (Executable)
The RETURN statement transfers control from a subprogram back to the
calling program unit.
-----------------------------------------------------------------------------------------------
| | | |
| Item | Description/Default | Restrictions |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| rtnnum | Integer expression specifying the | See "Semantics". |
| | alternate return number. | |
| | | |
-----------------------------------------------------------------------------------------------
Semantics
Normally, control returns from a subroutine to the calling program unit
at the statement following the CALL statement. Specifying alternate
return statements allows return to the calling program unit at any
labeled executable statement within it.
When the RETURN statement occurs in a subroutine subprogram and no
alternate return is specified, control returns to the first executable
statement following the CALL statement that invoked the subroutine.
When the RETURN statement occurs in a function, control returns to the
statement containing the function call. Alternate returns are not
allowed in functions.
The scalar expression, rtnnum, may have the range of values 1 to n, where
n is the number of alternate returns specified in the CALL statement.
The value of rtnnum identifies the ordinal position of the statement
label in the actual argument list of the CALL statement.
The asterisks in the SUBROUTINE statement are for documentation purposes.
The number of asterisks should be the same as the number of statement
labels in the CALL statement. For consistency with the ANSI standard, if
rtnnum is a constant, its value should be less than or equal to the
number of asterisks in the SUBROUTINE statement. However, if the value
of rtnnum exceeds the number of asterisks in the SUBROUTINE statement,
compilation, load, and execution are not affected. An error is generated
if alternate returns are specified and no asterisks appear in the
SUBROUTINE statement.
When the value of rtnnum is not in the range 1 to n, control returns to
the statement following the CALL statement. When a variable or
expression represents rtnnum, only one asterisk is required in the
SUBROUTINE statement, although it is good programming practice to have
the number of asterisks in the SUBROUTINE statement always match the
number of labels in the CALL statement.
rtnnum may have any numeric data type. If rtnnum is not an integer, it
will be converted to one. If the $HP1000 ARRAYS compiler directive is in
effect, rtnnum may be an array name. If rtnnum is an array name, the
first element of the array will be used.
Examples Notes
---------------------------------------------------------------------------------------
PROGRAM main The CALL statement specifies three possible
: return labels, plus the normal return point
CALL matrx (*10,m,*20,n,k,*30) (the statement following the CALL).
:
10...! executable statement
:
20...! executable statement
:
30...! executable statement
:
END
SUBROUTINE matrx(m,n,k,*,*,*) The SUBROUTINE statement contains a number
: of asterisks equal to the number of
k=2 statement labels in the CALL statement.
:
RETURN k k evaluates to the value 2, causing control
END to pass to the second alternate return
label specified in the CALL statement (20).
If k evaluates to a value outside the range
1 to 3, control returns to the statement
following the CALL statement.
MPE/iX 5.0 Documentation