RETURN |
![]() ![]() ![]() |
The RETURN statement returns from an internal subroutine entered by GOSUB or an external subroutine entered by CALL.
Format
RETURN {TO label{:}} RETURN expr
where
The RETURN statement returns from the most recent GOSUB or CALL statement. Thus the same RETURN statement could leave either an internal or catalogued subroutine.
The optional TO label clause causes return from a GOSUB to continue execution at the given label rather than at the statement following the GOSUB. This clause is ignored when returning from a CALL. Excessive use of RETURN TO can lead to programs that are extremely difficult to maintain.
Where a subroutine needs to return to the calling routine but it is not known how many internal subroutines may be active (e.g. in error paths), it is useful to write a statement of the form
ERROR.LABEL: RETURN TO ERROR.LABEL
This will cause all internal subroutines to return to the RETURN statement and then return to the calling program. This is different from STOP which would also terminate the current sentence.
The RETURN expr form of the RETURN statement is only valid in a FUNCTION and returns expr as the result of the function. If no RETURN statement of this form is executed by the function, a null string is returned.
Examples
SUBROUTINE PRINT.REPORT(ID) ...statements... RETURN END
This skeleton subroutine performs its task and then returns to its caller.
FUNCTION MATMAX(MAT A) MAX = A(1) N = INMAT(A) FOR I = 1 TO N IF A(I) > MAX THEN MAX = A(I) NEXT I
RETURN MAX END
This function scans a one dimensional matrix and passes back the value of the largest element.
|