Do-while, Do-while -3, Purpose – Rockwell Automation 1746-BAS BASIC LANGUAGE User Manual

Page 87: Syntax, Examples

Advertising
background image

Publication 1746-RM001A-US-P

Control Functions 7-3

DO-WHILE

Purpose

Use the DO-WHILE statement to set up loop control within a module program.
The operation of this statement is similar to the DO-UNTIL [rel expr]. 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
(example: DO-WHILE, DO-UNTIL, FOR-NEXT and BASIC subroutines). The
control stack is 157 bytes long. DO-WHILE and DO-UNTIL loops and GOSUB
commands use 3 bytes of the control stack. FOR-NEXT loops use 17 bytes.

Syntax

DO-WHILE [rel expr]

Examples

Simple DO-WHILE

>NEW

>1

REM EXAMPLE PROGRAM

>10 DO

>20 A = A + 1

>30 PRINT A

>40 WHILE A < 4

>50 PRINT “DONE”

>60 END

READY

>RUN

1

2

3

4

DONE

READY

>

Nested DO-WHILE

>NEW

IMPORTANT

Excessive nesting exceeds the limits of the control stack,
generating an error, and causing the module to enter Command
mode.

Advertising