Professional Documents
Culture Documents
Exit Statement - Visual Basic - Microsoft Docs
Exit Statement - Visual Basic - Microsoft Docs
Docs / .NET / Visual Basic guide / Language reference # Bookmark D Feedback / Edit + Share
Language Reference
T
T
Statements
Language Reference
Attributes Do exits the innermost loop and transfers control to the next higher level of nesting.
T
T Functions within nested For loops, Exit For exits the innermost loop and transfers control to the next higher level
T
T Modifiers of nesting.
Modules
Exit Function
Nothing
Immediately exits the Function procedure in which it appears. Execution continues with the statement
T
T Objects
following the statement that called the Function procedure. Exit Function can be used only inside a
T
T Operators
Function procedure.
Properties
T
T Queries To specify a return value, you can assign the value to the function name on a line before the Exit
Function statement. To assign the return value and exit the function in one statement, you can instead use
Statements
T
T
A-E Statements Immediately exits the Property procedure in which it appears. Execution continues with the statement
AddHandler Statement that called the Property procedure, that is, with the statement requesting or setting the property's value.
Call Statement Exit Property can be used only inside a property's Get or Set procedure.
Class Statement
To specify a return value in a Get procedure, you can assign the value to the function name on a line
Const Statement
before the Exit Property statement. To assign the return value and exit the Get procedure in one
Continue Statement statement, you can instead use the Return statement.
Declare Statement
In a Set procedure, the Exit Property statement is equivalent to the Return statement.
Delegate Statement
Error Statement In a Sub procedure, the Exit Sub statement is equivalent to the Return statement.
Event Statement
Exit Try
Exit Statement
Immediately exits the Try or Catch block in which it appears. Execution continues with the Finally block
T
T F-P Statements if there is one, or with the statement following the End Try statement otherwise. Exit Try can be used
T
T Q-Z Statements only inside a Try or Catch block, and not inside a Finally block.
T
T Clauses
Exit While
Declaration Contexts and Default
Immediately exits the While loop in which it appears. Execution continues with the statement following the
Access Levels
End While statement. Exit While can be used only inside a While loop. When used within nested
Attribute List
While loops, Exit While transfers control to the loop that is one nested level above the loop where Exit
Parameter List
While occurs.
Type List
T
T XML Comment Tags
T
T XML Axis Properties Remarks
T
T XML Literals
Do not confuse Exit statements with End statements. Exit does not define the end of a statement.
T
T Error Messages
T
T Reference
VB = Copy
Debug.WriteLine("")
' Output: 0 1 2 3 4 5 6 7 8 9 10
Example
The following example assigns the return value to the function name myFunction , and then uses Exit
Function to return from the function:
VB = Copy
Example
The following example uses the Return Statement to assign the return value and exit the function:
VB = Copy
See also
Continue Statement
Do...Loop Statement
End Statement
For Each...Next Statement
For...Next Statement
Function Statement
Return Statement
Stop Statement
Sub Statement
Try...Catch...Finally Statement
Feedback
! English (United States) 0 Theme Previous Version Docs Blog Contribute Privacy & Cookies Terms of Use Trademarks © Microsoft 2021
- Download PDF