beautypg.com

Rpbasic-52 programming guide, On goto – Remote Processing BASIC 52 User Manual

Page 90

background image

RPBASIC-52 PROGRAMMING GUIDE

2-71

ON GOTO

Syntax:

O N expr G O T O l in e 0 [, li n e1 [ li n e2 . .. ] ]

Function:

Branches to a program line based on expr value.

valuate to greate r than or equal to ze ro; if expr evaluates to ze ro, execution bran ches to {0th line# }; if expr
evaluates to one, execution branches to {1st line#}, etc. Commas shown are required.
Mode:

Run

Use:

ON A/5 GO TO 100, 200, 500

Cards:

All

D E S C R IP T I ON

The ON-GO TO 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 ne cessa ry, expr is truncated to an inte ger.

One or m ore of the program lines may b e the same , to GOTO the same lo cation with differe nt expr value s.
A t l ea s t o n e pr o gr a m li n e m u s t b e p ro v id e d . P r og r am l i ne s m a y o c c ur i n a n y or d er , f o r e x a m pl e , O N A
GOTO 500,700,600.

RELATED

G O T O , G O S UB , O N -G O S U B

ERRORS

B A D A R G U M E N T The value of expr is less than 0.
B A D S Y N T A X

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
t h e O N - G O T O .

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