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+ #GO SUB
2+
3+
4+ ##Syntax
5+ ```
6+ GO SUB <label>
7+ GOSUB <label>
8+ ```
9+ Continues the execution at the given label or line number.
10+ The current execution point is pushed (stored) onto the stack,
11+ to be recovered later.
12+
13+ When a [ RETURN] ( return.md ) is found and executed, the previous
14+ execution point is popped out (recovered) from the stack and
15+ continues just after the GO SUB. This is a way to create simple
16+ subroutines.
17+
18+ This sentence exists just for compatibility with legacy BASIC
19+ dialects. You should use [ SUB] ( sub.md ) or [ FUNCTION] ( function.md ) instead.
20+
21+ GO SUB cannot be used within neither subroutines nor functions.
22+ You can't GOSUB into a function or sub. So GOSUB is limited to
23+ global [ scope] ( scope.md )
24+
25+ > ** WARNING** : Using GO SUB continuously without returning with
26+ > RETURN will eventually fill the stack (stack overflow) and crash
27+ > your program.
28+
29+ ### Example with GO SUB
30+
31+ ```
32+ 10 LET number = 10
33+ 20 GOSUB 1000 : REM calls the subroutine
34+ 30 LET number = 20
35+ 40 GOSUB 1000 : REM calls the subroutine again
36+ 100 END : REM the program must end here to avoid entering the subroutine without using GOSUB
37+ 1000 REM Subroutine that prints number + 1
38+ 1010 PRINT "number + 1 is "; number + 1
39+ 1020 RETURN : REM return to the caller
40+ ```
41+
42+ This will output:
43+
44+ ```
45+ number + 1 is 11
46+ number + 1 is 21
47+ ```
48+
49+
50+ ##Remarks
51+ * This statement is Sinclair BASIC compatible.
52+ * GO SUB cannot be used within subrutines nor functions.
53+
54+ ##See also
55+ * [ RETURN] ( return.md )
56+ * [ FUNCTION] ( function.md )
57+ * [ SUB] ( sub.md )
Original file line number Diff line number Diff line change 1- #RESTORE
1+ #RETURN
22
33
44##Syntax
You can’t perform that action at this time.
0 commit comments