Do...Loop Statement Example

This example shows how Do...Loop statements can be used. The inner Do...Loop statement loops 10 times, sets the value of the flag to False, and exits prematurely using the Exit Do statement. The outer loop exits immediately upon checking the value of the flag.

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.