On Goto

From Br Wiki
Jump to: navigation, search

The On GoTo (ON GOT) statement evaluates a numeric expression, then transfers program control to another line according to the expression's value.

Comments and Examples

ON GOTO matches the rounded integer value of an expression to its corresponding line-ref. If the value is 2, for instance, program control transfers to the line indicated by the second line-ref.

In the following example, control transfers to line 10 when Day is 1, to line 50 when Day is 3, and to line 90 when Day is 5. If Day rounds off to less than 1 or more than 5, control goes to line 110.

02220 ON DAY GOTO 10,30,50,70,90 NONE 110


ON <numeric expression> GOTO <line ref>[,...] [NONE <line ref>] [<error condition> <line ref>][,...]



1.) Transfer control to the next line or statement if there is no corresponding line reference.
2.) Interrupt the program if an error occurs and ON is not active.


ON GOTO has two required parameters. "Numeric expression" is the numeric expression that the system is to evaluate. The value of this expression is rounded off and matched to the position number of the "line-ref", which is the line number or label to which it transfers. You must specify at least one line-ref in each ON GOTO statement. If the numeric expression has a value that rounds off to less than 1 or greater than the total number of line-refs specified, program control goes to the line listed in the optional "NONE line-ref" parameter. (Otherwise, control automatically goes to the next executable statement.) This branch is treated as a GOTO branch rather than an error- processing branch. ON GOTO allows error processing with the optional "error-cond line-ref" parameter. See Error Conditions for more information.