Description
Provides the means for internal branching.
Syntax
GoSub label
Parameters
The GoSub statement has the following parameter.
Parameter | Description |
---|---|
label | May be any valid numeric or alphanumeric label. An alphanumeric label must start with an alphabetic character. |
When BASIC+ encounters a GoSub statement, it transfers control of the program to the internal subroutine designated by the label, where the label is the only word on a line and the next line is the first line of the internal subroutine. The statements within the subroutine are executed in sequence until a Return is encountered. The control then transfers back to the statement following the GoSub statement.
Use labels descriptively. Proper use of a label can help you understand the purpose of a subroutine, especially after some time has passed since you (or someone else) wrote it.
Use GoSub and Return rather than GoTo for branching to and from subroutines. GoSub and Return make structured programming easier to follow.
See also
GoTo, On...GoSub, On...GoTo, Return
Example
/* The following code fragment shows how to branch to internal subroutines, as well as how to return execution to the main program. */ Main: If Len(InvoiceAmount) Then Discount = .10 ;* ten percent GoSub FindTotal End Else GoSub PrepareInvoice End Return FindTotal: * processing here... Return PrepareInvoice: * processing here... Return