GOSUB Statement
Transfers control to the subroutine with the specified label.
Syntax
GOSUB statement-label
Syntax Elements
statement-label is the label of the statement where control is to be transferred.
Operation
GOSUB transfers control to a subroutine specified by statement-label, and execution continues sequentially from that statement until a RETURN statement is encountered.
The RETURN statement returns control to the statement immediately following the GOSUB statement that called the subroutine.
The RETURN TO statement returns control to a specific statement specified by statement-label.
If the GOSUB or a RETURN TO statement refers to a statement-label that does not exist, an error message is printed at compile time.
GOSUB statements can be nested with up to 199 levels of nesting possible.
See Also
Example
10 GOSUB 30
15 PRINT X1
.
.
.
STOP
30 * SUBROUTINE
.
.
IF ERROR RETURN TO 99
40 RETURN
99 * ERROR RETURN HERE
Transfers control to statement 30. The subroutine is executed. If the logical variable error is true (1), the conditional RETURN TO 99 path is taken: otherwise, control passes back to the statement at label 15.