25.72. GOSUB label

[<<<] [>>>]

=H Gosub commands

This is the good old way implementation of the BASIC GOSUB command. The command GOSUB works similar to the command GOTO with the exception that the next return command will drive the interpreter to the line following the line with the GOSUB.

You can only call a code segment that is inside the actual code environment. In other words if the GOSUB is in a function or subroutine then the label referenced by the GOSUB should also be in the same function or subroutine. Similarly any GOSUB in the main code should reference a label, which is also in the main code.

To return from the code fragment called by the command GOSUB the command RETURN should be used. Note that this will not break the execution of a function or a subroutine. The execution will continue on the command line following the GOSUB line.

GOSUB commands can follow each other, ScriptBasic will build up a stack of GOSUB calls and will return to the appropriate command line following the matching GOSUB command.

When a subroutine or function contains GOSUB commands and the function or subroutine is finished so that one or more executed GOSUB command remains without executed RETURN then the GOSUB/RATURN stack is cleared. This is not an error.

See also RETURN.

[<<<] [>>>]