Do-while – Rockwell Automation 1771-DB BASIC MODULE User Manual
Page 161

Chapter
Statements
11
11 -9
Use the DO-WHILE statement to set up loop control within a module
program. This statement is similar to the DO-UNTIL rel expr (page
11 -8). All statements between the DO and the WHILE rel expr are
executed as long as the relational expression following the WHILE
statement is true. You can nest DO-WHILE statements.
The control stack (C-stack) stores all information associated with loop
control. The C-stack is 157 bytes long. DO-WHILE 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. An error
occurs and the module enters Command mode. For more information see
control stack, page 8 -1.
Syntax
DO-WHILE
rel expr
Example
Simple DO-WHILE
Nested DO-WHILE
>10 DO
>10 A=0 : C=0
>20 A = A + 1
>20 DO
>30 PRINT A
>30 A=A+1
>40 WHILE A < 2
>40 DO
>50 END
>45 C=C+1
READY
>50 PRINT A,C,A*C
>RUN
>60 WHILE C<>3
1
>70 C=0
2
>80 WHILE A<4
>90 END
READY
>RUN
1 1 1
1 2 2
1 3 3
2 1 2
2 2 4
2 3 6
3 1 3
3 2 6
3 3 9
4 1 4
4 2 8
4 3 12
DO-WHILE