Do…Loop Statement

Runs a sequence of statements while a given condition is true, or until a condition becomes true.

Syntax

Pre-condition construct

Do { While | Until } condition
    [ statements ]
Loop

Post-condition construct

Do
    [ statements ]
Loop { While | Until } condition

Parts

Do
Mandatory start of the statement.
While
Mandatory unless you use Until. The loop runs statements until condition becomes false.
Until
Mandatory unless you use While. The loop runs statements until condition becomes true.
condition
Mandatory Boolean expression.
statements
Optional one or more statements between Do and Loop. These run while condition is true, or until condition becomes true.
The alternative is two or more groups of statements. The first group starts with Exit When, and runs the same as specified above. The subsequent groups start with When, and run when (1) the statements after Begin cannot start, or (2) after they complete. See the When statements section for more information.
Loop
Completes the statement.

Instructions

Use Do…Loop when you must run one or more statements again and again. It is recommended when you cannot be sure how many times the statements must run. Control is connected with the Boolean condition that you supply. The pre-condition construct is equivalent to the statement While, but Do…Loop is more flexible. If you must run the statements a known number of times, the statement For can give better performance.

Usual pre-conditional operation

TODO

Usual post-conditional operation

TODO

Exit Do

The statement Exit Do can stop the operation of Do…Loop. Exit Do immediately moves control to the statement after Loop.

When statements

To find if a loop with Do While completed because condition became false, use the statement When DONE.

To find if a loop with Do While was not run because condition was initially false, use the statement When NONE.

The post-condition construct does not let you use When NONE. The statements always run a minimum of one time, because the condition comes last.

See Exit When Clause for more information.

Examples

Do While
Loop
Do
Loop While

See also