Do ... Loop statement
Repeats a block of statements before the condition is true or if the condition becomes true .
Do [{While | Until} condition]
[statements]
[Exit Do]
[statements]
Loop
You can also use the following syntax:
Do
[statements]
[Exit Do]
[statements]
Loop [{While | Until} condition]
Parameters
Condition
A numeric or string expression with a value of True or False. If condition is Null, the condition is treated as False.
Statements
One or more commands that are executed repeatedly when condition is True .
Description
Exit do can only be used in do ... Loop Control statement, provide another exit from do ... The Loop method. Can be in do ... any position in the Loop statement to place any Exitdo. Exit do is usually associated with a conditional judgment statement (for example, if ...). Then ), passing control to the statement immediately following the Loop statement.
When used to nest do ... In Loop ,Exit do passes control to the upper-level nested loop of the loop in which it resides.
The following example shows how to use the Do ... Loop Statement:
Do Until DefResp = vbNo MyNum = Int (6 * Rnd + 1)
'
Produce 1
To 6
The random number between. DefResp = MsgBox (MyNum & "
Want another number?", vbYesNo)
Loop
Dim Check, Counter
Check = True: Counter = 0
'
Initializes the variable. do
'
outer loop. Do while Counter <
' The
inner loop. Counter = Counter + 1
'
to increase the counter. if Counter = Then
'
if the condition is True ...
Check = False
'
sets the flag value to False
. Exit do
'
terminates the inner loop. End If
Loop
Loop Until Check = False
' The
terminates the outer loop immediately.