ON GOTO

ON GOTO

Top  Previous  Next

 

The ON GOTO statement jumps to one of a list of labels depending on the value of an expression.

 

 

Format

 

ON expr GOTO label1{:}, label2{:}, label3{:}

ON expr GO {TO} label1{:}, label2{:}, label3{:}

 

where

 

expris an expression which can be resolved to a numeric value

 

label1...are statement labels. The trailing colons are optional and have no effect on the behaviour of the statement.

 

The ON GOTO statement may be written over multiple lines by inserting a newline after the comma separating two labels.

 

Execution of the program continues at label1 if the value of expr (converted to an integer) is 1, label2 if it is 2 and so on. By default, a value less than one will use label1 and a value greater than the number of labels in the list will use the last label. The PICK.JUMP.RANGE option of the $MODE directive can be used to invoke the Pick style behaviour where an out of range value continues execution at the statement following the ON GOTO.

 

 

 

Example

 

ON ACTION GOTO DISPLAY.REPORT,

              PRINT.REPORT,

              SAVE.REPORT

 

This program fragment jumps to one of three labels depending on the value of variable ACTION. If ACTION could not be guaranteed to hold a valid value (1 to 3), error checking statements should be included to ease debugging of program errors.