Do...Loop Statement

Language Items List

Definition:

Repeats a group, or block, of statements while a condition is true or until a condition becomes true.

Syntax (1):

Do[{While | Until} condition]
[statementblock]
[Exit Do]
[statementblock ]
Loop

Syntax (2):

Do
[statementblock]
[Exit Do]
[statementblock]
Loop[{While | Until} condition]


Syntax Description


Do The first statement in a Do...Loop control structure.

While Executes the statementblock while the condition is true.

Until Executes the statementblock until the condition becomes true.

condition A numeric or string expression that evaluates true (-1 or any nonzero numeric value) or false (0 or Null).

statementblock Program lines between the Do and Loop statements that are executed repeatedly while a condition exists or until the condition is met.

Exit Do Provides an alternate way to exit a Do...Loop. It can only be used within the Do...Loop control structure. You can place any number of Exit Do statements anywhere in the Do...Loop. Exit Do skips any commands between it and the Loop keyword, exits the loop, and transfers control to the statement immediately following the loop.

Loop The last statement in a Do...Loop control structure. It signals the end of the statement block that is the body of the loop.

Details:

With Phoenix you can combine the syntax elements in various ways to perform five types of Do...Loops:


Loop Type Description


Do While...Loop Checks the condition then executes the statement block while the condition is True. Repeats execution of the loop until the condition is false.

Do Until...Loop Checks the condition then executes the statement block while the condition is False. Repeats execution of the loop until the condition evaluates as a nonzero value.

Do...Loop While Executes the statement block once, then checks the condition. If the condition is True, execution is repeated until the condition is False.

Do...Loop Until Executes the statement block once, then checks the condition. If the condition is False, execution is repeated until the condition is True.

Infinite Do...Loop Executes the statement block continuously without end. Must use an "Exit Do" statement to terminate the loop.


Note: If you create an infinite loop, be sure to provide a trigger that will exit the loop. Exit Do is commonly used for this purpose. You should also provide a means for your program to continue performing any other needed tasks. For example to make the interface
live again you might call DoEvents().

If an object reference variable is used for a condition, it will be True if the reference points to an object, it will evaluate to False if the reference is Nothing.

See Also:

Exit
For...Next
While...Wend

With Statement