Goto, Goto -7, Purpose – Rockwell Automation 1746-BAS BASIC LANGUAGE User Manual

Page 91: Syntax, Example

Advertising
background image

Publication 1746-RM001A-US-P

Control Functions 7-7

In the first example, since E-0, C-10, D-2, and the PRINT statement at line 20
executes 6 times, the values of A that are printed are 0, 2, 4, 6, 8 and 10. A
represents the name of the index or loop counter. The value of E is the starting
value of the index. The value of C is the limit value of the index and the value of D
is the increment to the index.

If the STEP statement and the value D are omitted, the increment value defaults to
1, therefore; STEP is an optional statement. The NEXT statement returns the loop
to the beginning of the loop and adds the value of D to the current index value.
The current index value is then compared to the value of C, the limit value of the
index.

If the index is less than or equal to the limit, control transfers back to the statement
after the FOR statement. Stepping backward (FOR I-100 TO 1 STEP-1) is
permitted in the module. The NEXT statement is always followed by the
appropriate variable. You may nest FOR-NEXT loops up to 9 times.

>1

REM EXAMPLE PROGRAM

>1

REM EXAMPLE PROGRAM

>10 FOR I=1 TO 4

>10 FOR I=0 TO 8 STEP 2

>20 PRINT I,

>20 PRINT I

>30 NEXT I

>30 NEXT I

>40 END

>40 END

>RUN

>RUN

>1 2 3 4

0

2

4

6

8

READY

READY

GOTO

Purpose

Use the GOTO statement to cause BASIC to transfer control to the line number
([ln num]) specified.

Syntax

GOTO [ln num]

Example

>1

REM EXAMPLE PROGRAM

>50 GOTO 100

Advertising