Do 迴圈

雖然 while 與迴圈非常相似,但是如果迴圈重複未知則通常會使用。

做同時:

'Continues until i is greater than 10
Do While i <= 10
    i = i + 1
Loop

'Or we can write it so the first loop always executes unconditionally:
'Ends after our first loop as we failed this condition on our previous loop
Do
    i = i + 1
Loop While i <= 10

直到:

'Ends once i equates to 10
Do Until i = 10
    i = i + 1
Loop

'Or we can write it so the first loop always executes unconditionally:
'Ends after our first loop as we failed this condition on our previous loop
Do
    i = i + 1
Loop Until i=10

退出 Do 迴圈類似於 for 迴圈,但只使用 Exit Do 語句。

'Exits after i equates to 10
Do Until i = 10
    i = i + 1
    If i = 7 Then Exit Do
Loop