HP Business BASIC/XL Reference Manual - HP 3000 MPE/iX Computer Systems - Edition 1 (32715-90001)

4-: 127
RETURN
The RETURN statement returns control to the program unit that called a
subroutine or multi-line function. When used in a subroutine, control is
returned to the statement following the GOSUB statement. When used in a
multi-line function, the value of the expression immediately following
RETURN is returned to the statement or expression where the call was made.
Syntax
RETURN [
expr
]
Parameters
expr
A numeric expression if the RETURN statement is in a
numeric function, and a string expression if the RETURN
statement is in a string function.
HP Business BASIC/XL evaluates the expression and
returns it value to the program unit that called the
function. If the function is numeric, HP Business
BASIC/XL converts the value to the function type before
return it (the function type is either declared in the
DEF FN statement that defines the function, or if not
declared is the default numeric type).
This parameter is not used when the RETURN is used in
conjunction with a subroutine.
If a multi-line function does not contain a RETURN statement, an error
occurs when execution reaches the FNEND statement. The multi-line
function RETURN statement that returns a value is legal only within a
multi-line function. It is illegal in the main program or a subprogram.
Examples
10 READ A !Example of RETURN within a multi-line function
20 C= FNAdd(A)
30 PRINT C
99 END
100 DEF FNAdd(X)
120 Y= X+2
130 RETURN Y !FNAdd returns value to line 20
140 FNEND
GOSUB statements can be nested; that is, calls to more than one GOSUB
statement can be executed before a RETURN statement is executed. The
first RETURN statement executed matches the most recently executed GOSUB
statement, the second RETURN statement executed matches the second most
recently executed GOSUB statement, and so on.
10 REM Main Program Unit
20 PRINT "B"
25 GOSUB First !Go to line 100; First prints "ASI"
30 PRINT "C"
35 STOP
100 First: REM First subroutine
110 PRINT "A";
120 GOSUB second !Go to line 200; Second prints "S"
130 PRINT "I"
140 RETURN !Return to line 25 to print "C"
200 Second: REM Second subroutine
210 PRINT "S";
220 RETURN !Return to line 130 to print "I"
999 END
The output from the above program is BASIC.