Do...Loop

The Do…Loop instructions are used to repeat a block of statements while a condition is true or until a condition becomes true.

Syntax 1

Do [{While | Until} condition]

          [statementblock]

          [ExitDo]

          [statementblock]

Loop

Syntax 2

Do

          [statementblock]

          [ExitDo]

          [statementblock]

>Loop [{While | Until} condition]

Remarks

The Do…Loop instruction has these parts:

Do

The Do statement declares the beginning of a Do…Loop. It must be the first statement in a Do...Loop control structure.

While

The While statement indicates that the loop is executed while the Condition is true.

Until

The Until statement Indicates that the loop is executed until the Condition is true.

Condition

The Condition is a numeric expression that is evaluated as True (nonzero) or False (0 or Null).

StatementBlock (Statement Block)

The StatementBlock is the portion of the program that should be repeated until the loop is terminated by the Condition. These instructions lie between the Do and Loop statements.

ExitDo (Exit Do Statement)

The ExitDo statement provides an alternate way to exit a Do...Loop. Any number of ExitDo statements may be placed anywhere in the Do...Loop. ExitDo statements are often used with the evaluation of some condition (for example, If...Then). When a Do…Loop is exited, control is transferred to the statement immediately following the Loop. When Do...Loop statements are nested, control is transferred to the Do...Loop that is one nested level above the loop in which the ExitDo occurs.

Loop

The Loop statement ends a Do...Loop control structure.