Mark Wickens

back to Command Reference

ON GOTO

[All Models]

Purpose

Jumps to a specified branch destination in accordance with a specified branching condition.

Format

ON     condition       GOTO    [ branch          [, [ branch
       └───┬───┘                destination ]       destination ] ]*
   Numeric expression

Branch destination:

  destination branch line number
  └─────────────┬──────────────┘
           Line number

  # program area number
    └────────┬────────┘
    Single character; 0~9

Example

ON A GOTO 100, 200, 300

Parameters

  1. branch condition: Numeric expression truncated to an integer
  2. line number: Integer in the range of 1 ≦ line number ≦ 65535
  3. program area number: Single character, 0~9

Explanation

  1. The GOTO statement is executed in accordance with the value of the expression used for the branch condition. For example, execution jumps to the first branch destination specified when the value is 1, to the second destination when the value is 2, etc.
  2. Program execution does not branch and execution proceeds to the next statement when the value of the branch condition is less than 1, or if a branch destination corresponding to that value does not exist.
  3. Up to 99 branch destinations may be specified.

Note

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).

See

Sample Program

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.