The GoSub (GOS) statement transfers program control to a subroutine. The GoSub statement may no longer be executed from the command line. Error 1011 (Illegal immediate statement) will occur if such usage is attempted.
Comments and Examples
GoSub is useful for transferring to and from computations or other subroutines that occur more than once in a program. In the following example, the program transfers to the subroutine that begins on line 900. If this particular line does not contain an executable statement, control is transferred to the next executable statement after line 900:
08450 GOSUB 9000 ... 09080 Return
GoSub works in conjunction with the Return statement, which is required at the end of every subroutine. Return automatically transfers control back to the statement immediately following the corresponding GoSub. This occurs even when the next statement is in the middle of a multiple-statement line.
GOSUB <line ref>
GoSub's only parameter, line-ref, is required. It identifies the line number or label that begins the desired subroutine.