On ... Goto Command
Obsolete
This command is replaced by the Case command.
Purpose
To select one of a series of labels to pass execution to, based on the numeric value of a variable or expression.
Syntax
on
variable
goto
label [...label]
Argument Explanation
- variable: May not be a constant or of Type String, and must have positive numeric values.
- label: Required, and additional labels may be provided, separated by spaces.
What It Does
The numeric value of variable is used as an index to select one of the listed labels to pass execution to. If the value of variable is 1, execution is passed to the first label; if the value of variable is 2, execution passes to the second, and so forth.
If the value of variable is less than 1 or greater than the number of labels listed, execution will go to the line following the on ... goto command.
on time goto early on_time late
In this example, when the value of variable time is 1, DataFlex passes execution to label early. When the value is 2, it goes to on_time, and when it is 3, it goes to late. When time has any other value, execution passes to the line after on ... goto.
Notes
-
You must provide a
labelin your program for everylabelin everyon ... gotocommand you use. -
If the value of
variableis less than 1 or greater than the total number oflabelson theon ... gotocommand line, no goto will be executed. If you want this to constitute an error in your program, declare the error as follows:on music goto rock country jazz if music gt 3 error 198 "INVALID MUSIC TYPE SELECTED"If the value of
musicis greater than 3, DataFlex declares Error 198. -
You may precede
on ... gotowith indicators and if tests. -
The
on ... gotocommand is similar to theon ... gosubcommand with the exception that theon ... gotocommand does not return to the line after theon ... gotocommand. -
If
variableis a number which includes a fractional (decimal) value, the value will be truncated to an integer value before theon ... gotoselection is made.