On-goto, On-goto -11, Purpose – Rockwell Automation 1746-BAS BASIC LANGUAGE User Manual

Page 95: Syntax, Example

Advertising
background image

Publication 1746-RM001A-US-P

Control Functions 7-11

ON-GOTO

Purpose

Use the ON-GOTO statement to transfer control to the line(s) specified by the
GOTO statement when the value of the expression following the ON statement is
encountered in the BASIC program.

Syntax

ON [expr] GOTO [ln num]

Example

>1

REM EXAMPLE PROGRAM

>10 ON Q GOTO 100,200,300

Control is transferred to line 100 if Q is equal to 0 and then to line 200 if Q is
equal to 1. If Q is equal to 2, control is transferred to line number 300, and so on.
All comments that apply to GOTO apply to the ON statement. If Q is less than
zero, an

ERROR: BAD ARGUMENT

message is generated and the BASIC module

enters Command mode. If Q is greater than the line number list following the
GOTO statement, an

ERROR: BAD SYNTAX

message is generated. The

ON-GOTO statement provides conditional branching options within the module
program.

Advertising