Warning
You're browsing the old v2.x documentation. This version is no longer maintained. Click here to go the v3.x documentation.
This is an old revision of the document!
GOSUB ... RETURN
Syntax:
gosub <label> label: [statements] return
The GOSUB
command calls a subroutine marked by a label. Return will pass control back to the caller. Nesting subroutines are supported (`GOSUB` and `RETURN` compiles to just plain `JSR` and `RTS`, nothing fancy). Stack overflow is not checked in runtime, but is quite unlikely to encounter. Example:
rem ** subroutines ** gosub first_routine end first_routine: print "hello world" gosub second_routine return second_routine: print "and hello again" return
Note #1: make sure to use the `END` command before your routines if you don't want them to be executed in the normal program flow (like in the example above).
Note #2: there is no runtime call stack checking (e. g. no `?RETURN WITHOUT GOSUB ERROR`). If your call stack is corrupted, the program is likely to break.
Note #3: Unlike procedures, subroutines do not open a new local scope.