Exit Do statement
优质
小牛编辑
141浏览
2023-12-01
当我们想要根据特定条件退出Do循环时,使用Exit Do语句。 它可以在Do…While和Do...Until循环中使用。
执行Exit Do ,控件会在Do循环后立即跳转到下一个语句。
语法 (Syntax)
以下是VBA中Exit Do Statement的语法。
Exit Do
<!--流程图 (Flow Diagram)
-->例子 (Example)
以下示例使用Exit Do 如果Counter的值达到10,则退出Do循环,控制在For循环后立即跳转到下一个语句。
Private Sub Constant_demo_Click()
i = 0
Do While i <= 100
If i > 10 Then
Exit Do ' Loop Exits if i>10
End If
MsgBox ("The Value of i is : " & i)
i = i + 2
Loop
End Sub
执行上述代码时,它会在消息框中输出以下输出。
The Value of i is : 0
The Value of i is : 2
The Value of i is : 4
The Value of i is : 6
The Value of i is : 8
The Value of i is : 10