Caché MultiValue Basic Reference
ON
[Home] [Back] [Next]
InterSystems: The power behind what matters   
Class Reference   
Search:    

Transfers program execution to one of several internal subroutines or labels.
Synopsis
ON integer GOSUB label1[,label2][...]

ON integer GOTO label1[,label2][...]
Arguments
integer A positive non-zero integer that corresponds to the list of labels.
label Any valid label. The label name can be optionally followed by a colon (:).
Description
The ON statement is used to transfer execution to one of the labels specified by the GOSUB or GOTO keyword. Which label to transfer execution to is specified by the integer argument: a value of 1 transfers control to the first listed label, a value of 2 transfers control to the second listed label, and so forth.
For a GOTO, this label identifies a line of code in the current program. For a GOSUB, this label identifies an internal subroutine that is executed until a RETURN statement is encountered. Execution then reverts to the line immediately following the ON...GOSUB statement. (Execution of an internal subroutine can also terminate with an END statement, which does not return control.)
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.
See Also