RETURN
RETURN
Section titled “RETURN”Syntax
Section titled “Syntax”RETURN [<expr>]
RETURN statement is used in 3 cases:
- When returning from a GO SUB sentence
- When returning (exiting) from a SUB (a subroutine)
- When returning (exiting) from a FUNCTION. In this case a return value must be specified.
Returns in the global scope (that is, outside any function or sub) are treated as return from GO SUB. Otherwise they are considered as returning from the function or sub they are into.
WARNING: Using RETURN in global scope without a GOSUB will mostly crash your program.
Use--stack-check
if you suspect you have this bug, to detect it.
Example with GO SUB
Section titled “Example with GO SUB”10 LET number = 1020 GOSUB 1000 : REM calls the subroutine30 LET number = 2040 GOSUB 1000 : REM calls the subroutine again100 END : REM the program must end here to avoid entering the subroutine without using GOSUB1000 REM Subroutine that prints number + 11010 PRINT "number + 1 is "; number + 11020 RETURN : REM return to the caller
This will output:
number + 1 is 11number + 1 is 21
Remarks
Section titled “Remarks”- This statement is Sinclair BASIC compatible.