While...Wend Statement Example

This example uses the While...Wend statement to increment a counter variable. The statements in the loop are executed as long as the condition evaluates to True.

Dim Counter
Counter = 0    ' Initialize variable.
While Counter < 20    ' Test value of Counter.
    Counter = Counter + 1    ' Increment Counter.
Wend    ' End While loop when Counter > 19.
Debug.Print Counter    ' Prints 20 in the Immediate window.