Exit 语句
退出「Do...Loop」「For...Next」、函数或子例程。
语法:
请参阅「参数」部分
参数:
「Exit Do」
仅在「Do...Loop」语句内有效,作用是退出循环。程序继续执行 Loop 语句之后的语句。如果「Do...Loop」语句是嵌套语句,控制将传递到下一个较高级别的循环中。
「Exit For」
仅在「For...Next 循环内有效,作用是退出循环。程序继续执行 Next」语句之后的第一条语句。在嵌套语句中,控制将传递到下一个较高级别的循环中。
「Exit Function」
立即退出「函数」过程。程序继续执行「函数」调用之后的语句。
「Exit Sub」
立即退出子例程。程序继续执行「子程序」调用之后的语句。
Exit 语句不能定义程序结构的结束,请勿与 End 语句混淆。
示例:
Sub ExampleExit
Dim sReturn As String
Dim sListArray(10) As String
Dim siStep As Single
For siStep = 0 To 10 ' 用测试数据填充数组
sListArray(siStep) = chr(siStep + 65)
MsgBox sListArray(siStep)
Next siStep
sReturn = LinSearch(sListArray(), "B")
Print sReturn
End Sub
Function LinSearch( sList(), sItem As String ) As Integer
Dim iCount As Integer
' LinSearch 搜索 TextArray:sList() 中的 TextEntry:
' 返回条目的索引或 0 (Null)
For iCount=1 To Ubound( sList() )
If sList( iCount ) = sItem Then
Exit For ' 找到 sItem
End If
Next iCount
If iCount = Ubound( sList() ) Then iCount = 0
LinSearch = iCount
End Function