Statements: if – then – else – Rockwell Automation 1771-DB Basic Module User Manual - Series A User Manual

Page 62

Advertising
background image

Operating Functions

Chapter 5

5–25

Unlike the RUN command the GOTO statement, if executed in the
COMMAND mode, does

not clear the variable storage space or

interrupts.

However, if the GOTO statement is executed in the

COMMAND mode after a line

is edited the module clears the variable

storage

space and all BASIC evoked interrupts. This is necessary

because

the variable storage and the BASIC program reside in the same

RAM memory. Because

of this editing a program can destroy variables.

Mode: RUN
Type:

CONTROL

The value

of the expression following the ON statement is the

number in the line list that control is transferred to.

Example:

u10 ON Q GOTO 100,200,300

If Q is equal to 0, control

is transferred to line number 100. If Q is

equal to 1, control is transferred to line number 200. If Q is equal to 2,
GOTO line 300, etc. All comments that apply to GOTO and

GOSUB

apply

to the ON statement. If Q is less than ZERO a BAD

ARGUMENT ERROR

is generated. If Q is greater than the line

number list

following the GOTO or GOSUB statement, a BAD

SYNTAX

ERROR is generated. The ON statement provides

“conditional branching”

options within the constructs of a BASIC

Module

program.

Mode: RUN
Type:

CONTROL

The IF statement sets up a conditional test. The general form of the IF –
THEN –

ELSE statement follows:

[ln num] IF [rel expr] THEN valid

statement ELSE valid

statement

Example:

u10 IF A=100 THEN A=0 ELSE A=A+1

5.4.13
Statement: GOTO [ln num]
(continued)

5.4.14
Statements: ON [expr] GOTO
[ln num], [ln num],...[ln num],
ON [expr] GOSUB[ln num],
[ln num],...[ln num]

5.4.15
Statements: IF – THEN –
ELSE

Advertising