Do...Loop
Synopsis
Do [{While | Until} condition] [statements] [Exit Do] [statements] Loop Or, you can use this syntax: Do [statements] [Exit Do] [statements] Loop [{While | Until} condition]
Arguments
The Do...Loop statement syntax has these parts:
condition | Numeric or string expression that is True or False. |
statements | One or more statements that are repeated while or until condition is True. |
Description
The Exit Do can only be used within a Do...Loop control structure to provide an alternate way to exit a Do...Loop. Any number of Exit Do statements may be placed anywhere in the Do...Loop. Often used with the evaluation of some condition (for example, If...Then), Exit Do transfers control to the statement immediately following the Loop.
When used within nested Do...Loop statements, Exit Do transfers control to the loop that is nested one level above the loop where it occurs.
Examples
The following examples illustrate use of the Do...Loop statement:
Do Until MyNum = 6
MyNum = Int (6 * Rnd + 1) ' Generate a random integer between 1 and 6
Println MyNum
Loop
Dim Check, Counter
Check = True: Counter = 0 ' Initialize variables.
Do ' Outer loop.
Do While Counter < 20 ' Inner loop.
Counter = Counter + 1 ' Increment Counter.
If Counter = 10 Then ' If condition is True...
Check = False ' set value of flag to False.
Exit Do ' Exit inner loop.
End If
Loop
Loop Until Check = False ' Exit outer loop immediately.
See Also
-
Exit Statement
-
For...Next Statement
-
While...Wend Statement