GOSUB
Synopsis
GOSUB label
Arguments
label | Any valid label. The label name can be optionally followed by a colon (:) |
Description
The GOSUB statement is used to transfer execution to the line of code identified by label. This label identifies an internal subroutine that is executed until a RETURN statement is encountered. Execution then reverts to the line immediately following the GOSUB statement.
Under the following circumstances control does not revert to the line following the GOSUB statement: The internal subroutine invokes an ENTER statement, or the internal subroutine terminates with an END statement.
The label argument value corresponds to line of code identified by a label identifier. Non-numeric labels end with a colon character; this colon is option when specifying the label argument.
The GOSUB statement is similar to GOTO, except that GOSUB permits a RETURN. The ON statement provides a way to select one of several GOSUB labels, based on an integer value.
Emulation
jBASE emulation uses the ONGO.RANGE option setting for handling out-of-range label values.
Examples
The following example illustrates the use of the GOSUB statement:
IF TIME()=0 THEN
GOSUB Midnight:
PRINT "Delayed",TIME()
ELSE
PRINT TIME()
END IF
Midnight:
PRINT "It's midnight, time is reset to 0"
SLEEP 1
RETURN