File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #RESTORE
2+
3+
4+ ##Syntax
5+ ```
6+ RETURN [<expr>]
7+ ```
8+ ** RETURN** statement is used in 3 cases:
9+
10+ 1 . When returning from a [ GO SUB] ( gosub.md ) sentence
11+ 2 . When returning (exiting) from a [ SUB] ( sub.md ) (a subroutine)
12+ 3 . When returning (exiting) from a [ FUNCTION] ( function.md ) . In this case a return value must be specified.
13+
14+
15+ Returns in the global scope (that is, outside any function or sub) are treated as return from [ GO SUB] ( gosub.md ) .
16+ Otherwise they are considered as returning from the function or sub they are into.
17+
18+ > ** WARNING** : Using RETURN in global scope without a GOSUB will mostly crash your program. <br >
19+ > Use ` --stack-check ` if you suspect you have this bug, to detect it.
20+
21+ ### Example with GO SUB
22+
23+ ```
24+ 10 LET number = 10
25+ 20 GOSUB 1000 : REM calls the subroutine
26+ 30 LET number = 20
27+ 40 GOSUB 1000 : REM calls the subroutine again
28+ 100 END : REM the program must end here to avoid entering the subroutine without using GOSUB
29+ 1000 REM Subroutine that prints number + 1
30+ 1010 PRINT "number + 1 is "; number + 1
31+ 1020 RETURN : REM return to the caller
32+ ```
33+
34+ This will output:
35+
36+ ```
37+ number + 1 is 11
38+ number + 1 is 21
39+ ```
40+
41+ ##Remarks
42+ * This statement is Sinclair BASIC compatible.
43+
44+ ##See also
45+ * [ GO SUB] ( gosub.md )
46+ * [ FUNCTION] ( function.md )
47+ * [ SUB] ( sub.md )
You can’t perform that action at this time.
0 commit comments