\<bookmark_value\>Exit statement\</bookmark_value\>

Exit Statement

Exits a \<emph\>Do...Loop\</emph\>, \<emph\>For...Next\</emph\>, a function, or a subroutine.

Syntax:


see Parameters

Parameters:

\<emph\>Exit Do\</emph\>

Only valid within a \<emph\>Do...Loop\</emph\> statement to exit the loop. Program execution continues with the statement that follows the Loop statement. If \<emph\>Do...Loop\</emph\> statements are nested, the control is transferred to the loop in the next higher level.

\<emph\>Exit For\</emph\>

Only valid within a \<emph\>For...Next\</emph\> loop to exit the loop. Program execution continues with the first statement that follows the \<emph\>Next\</emph\> statement. In nested statements, the control is transferred to the loop in the next higher level.

\<emph\>Exit Function\</emph\>

Exits the \<emph\>Function\</emph\> procedure immediately. Program execution continues with the statement that follows the \<emph\>Function\</emph\> call.

\<emph\>Exit Sub\</emph\>

Exits the subroutine immediately. Program execution continues with the statement that follows the \<emph\>Sub\</emph\> call.

Note Icon

The Exit statement does not define the end of a structure, and must not be confused with the End statement.


Example:


Sub ExampleExit
Dim sReturn As String
Dim sListArray(10) As String
Dim siStep As Single
    For siStep = 0 to 10 REM Fill array with test data
        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 searches a TextArray:sList() for a TextEntry:
REM Returns the index of the entry or 0 ( Null)
    For iCount=1 To Ubound( sList() )
        If sList( iCount ) = sItem Then
            Exit for REM sItem found
        End If
    Next iCount
    If iCount = Ubound( sList() ) Then iCount = 0
    LinSearch = iCount
End Function

Please support us!