GOSUB
Format: GOSUB expr
Supported by: COMX BASIC V1.00, Floating Point BASIC 2.2, Pecom 32 BASIC, Pecom 64 BASIC 1.0 and 4.0, Quest Super BASIC 1.4, 3.0, 5.0 and 6.0, RCA BASIC3 V1.1, Telmac SBASIC v 24.3
Similar commands: -
This statement (subroutine call) is identical to the GOTO statement with the exception that the program remembers where the GOSUB occurred. When BASIC encounters a RETURN statement, it will return to the statement following the last GOSUB statement executed. In this way subroutines may be nested as deep as memory will allow (the stack grows as the number of nested GOSUB's grows). An example of the GOSUB statement is
For example
5 A=2000 10 GOSUB 1000: GOSUB 1000 20 GOSUB A 30 END 1000 PR "DONE--" 1010 RETURN 2000 PR "FINISHED" : GOSUB 3000: GOTO 1010 3000 PR "COMPLETE": RETURNThis example results in the following being printed.
DONE--
DONE--
FINISHED
COMPLETE