Do-until – Rockwell Automation 1771-DB BASIC MODULE User Manual

Page 160

Advertising
background image

Chapter
Statements

11

11 -8

Use the DO-UNTIL statement to set up loop control within a module
program. All statements between the DO and the UNTIL rel expr are
executed until the relational expression following the UNTIL statement is
true. You can nest DO-UNTIL loops.

The control stack (C-stack) stores all information associated with loop
control. The C-stack is 157 bytes long. DO-UNTIL loops use 3 bytes of
the C-stack.

Do not improperly exit this loop or a C-stack error occurs. See CLEARS
(page 11 -3).

Important: Excessive nesting exceeds the limits of the C-stack, generating
an error, and causing the module to enter Command mode.
For more information see control stack, page 8 -1.

Syntax

DO-UNTIL

rel expr

Example

Simple DO-UNTIL

Nested DO-UNTIL

>1 REM EXAMPLE PROGRAM

>1 REM EXAMPLE PROGRAM

>10 A=0

>10 DO

>20 DO

>20 A=A+1

>30 A=A+1

>30 DO

>40 PRINT A

>40 C=C+1

>50 UNTIL A=4

>50 PRINT A,C,A*C

>60 PRINT “DONE”

>60 UNTIL C=3

>70 END

>70 C=0

>RUN

>80 UNTIL A=3

1

>90 END

2

>RUN

3

1 1 1

4

1 2 2

DONE

1 3 3

>READY

2 1 2

2 2 4

2 3 6

3 1 3

3 2 6

3 3 9

>READY

DO-UNTIL

Advertising