Description
The Do...Loop statement repeats a block of statements while a condition is True or until a condition becomes True.
This statement has the following forms:
Do [{While | Until} condition]
[statements]
[Exit Do]
[statements]
Loop
Do
[statements]
[Exit Do]
[statements]
Loop [{While | Until} condition]
Parameter | Description |
---|---|
Do | (required) Starts the definition of the loop |
While | (required, unless Until is used) Specifies that the loop should be repeated until condition is False |
Until | (required, unless While is used) Specifies that the loop should be repeated until condition is True |
condition | (optional) Specifies a numeric or string expression that is True or False. If condition is Null, condition is treated as False |
statements | (optional) Specifies one or more statements that are repeated while or until condition is True |
Exit Do | (optional) Transfers control out of the loop |
Loop | (required) Ends the definition of the loop |
Examples
The following example shows the basic use of this statement:
i = 0
Do
Msgbox("i = " & i)
i = i + 1
Loop While i < 5
This produces the following result (each line in a separate pop-up message box):
i = 0
i = 1
i = 2
i = 3
i = 4
Miscellaneous Information
Supported in Version: | 1.0 |
---|