Basic programming guide, On goto – Remote Processing BASIC for the CX-10 Modbus User Manual
Page 46

BASIC PROGRAMMING GUIDE
2-37
ON GOTO
Syntax:
ON expr GOTO line0[,line1[line2...]]
Function:
Branches to a program line based on expr value.
valuate to greater than or equal to zero; if expr evaluates to zero, execution branches to {0th line#}; if expr
evaluates to one, execution branches to {1st line#}, etc. Commas shown are required.
Mode:
Run
Use:
ON A/5 GOTO 100, 200, 500
DESCRIPTION
The ON-GOTO instruction conditionally branches to linen where 'n' is the value of expr. The expr must
evaluate to greater than or equal to zero. When expr evaluates to zero, execution branches to line0. When
expr evaluates to one, execution branches to line1, etc. If necessary, expr is truncated to an integer.
One or more of the program lines may be the same, to GOTO the same location with different expr values.
At least one program line must be provided. Program lines may occur in any order, for example, ON A
GOTO 500,700,600.
RELATED
GOTO, GOSUB, ON-GOSUB
ERRORS
BAD ARGUMENT The value of expr is less than 0.
BAD SYNTAX
The expr value is greater than the number of {"nth" line#} numbers provided, or
commas were omitted between {line#} values, or no line numbers were provided after
the ON-GOTO.
EXAMPLE
10
P=2
20
ON P GOTO 1000,2000,3000
30
END
1000
PRINT "Line 1000"
1010
END
2000
PRINT "Line 2000"
2010
END
3000
PRINT "Line 3000"
3010
END
>run
Line 3000