back to Command Reference
[All Models]
Jumps to a specified branch destination in accordance with a specified branching condition.
ON condition GOTO [ branch [, [ branch
└───┬───┘ destination ] destination ] ]*
Numeric expression
Branch destination:
destination branch line number
└─────────────┬──────────────┘
Line number
# program area number
└────────┬────────┘
Single character; 0~9
ON A GOTO 100, 200, 300
Branch destinations can specify a program area number using the #n syntax
(e.g., #2) to transfer execution to another program area. When branching to
another program area, execution continues from the beginning of that program area’s
code (or from the specified line number if one is given in that area).
10 INPUT "1 OR 2"; A
20 ON A GOTO 40, 50
30 END
40 PRINT "ONE" : END
50 PRINT "TWO"
Execution jumps to line 40 if 1 EXE is entered or to line 50 if 2 EXE is entered.
Otherwise, execution terminates at line 30.