GoSub

From BR Wiki
Revision as of 21:25, 18 January 2013 by Laura (talk | contribs) (Created page with "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 imm...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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 900

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.

Syntax

Parameters

GoSub's only parameter, line-ref, is required. It identifies the line number or label that begins the desired subroutine.

Technical Considerations

  1. Return information for the GoSub statement is kept in the FlowStack. (See BRConfig.sys)
  2. See the On GoSub statement for a method of calling one of several subroutines depending on the value of a numeric expression.
  3. Active GoSubs may not be altered during program interruption.