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