Exit Statement

Exits a Do...Loop, For...Next, a function, a property, or a subroutine.


Exit Do, Exit For, Exit Function, Exit Property, Exit Sub


Exit Do

僅在 Do...Loop 陳述式內有效,作用是結束迴圈。程式繼續執行 Loop 陳述式之後的陳述式。如果 Do...Loop 陳述式是嵌套陳述式,則將控制傳遞到下一個更高層級的迴圈中。

Exit For

僅在 For...Next 迴圈內有效,作用是結束迴圈。程式繼續執行 Next 陳述式之後的第一條陳述式。在嵌套陳述式中,則將控制傳遞到下一個更高層級的迴圈中。

Exit Function

立即結束 Function 程序。程式繼續執行 Function 呼叫之後的陳述式。

Exit Property

Exits the Property procedure immediately. Program execution continues with the statement that follows the Property call.

Exit Sub

立即結束子常式。程式繼續執行 Sub 呼叫之後的陳述式。


Exit 陳述式不能定義程式結構的結束,請勿與 End 陳述式混淆。


Sub ExampleExit
Dim sReturn As String
Dim sListArray(10) As String
Dim siStep As Single
    For siStep = 0 to 10  REM 用測試資料來填入陣列
        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
REM LinSearch 搜尋 TextEntry 的 TextArray:sList():
REM 傳回條目的索引或 0 (空)
    For iCount=1 To Ubound( sList() )
        If sList( iCount ) = sItem Then
            Exit for REM 找到 sItem
        End If
    Next iCount
    If iCount = Ubound( sList() ) Then iCount = 0
    LinSearch = iCount
End Function

Please support us!