Name
Exit Statement
Syntax
Exit Do Exit For Exit Function Exit Property Exit Select Exit Sub Exit Try Exit While
Description
Prematurely exits a block of code
Rules at a Glance
-
Exit Do Exits a
Do...Loopstatement. If the currentDo...Loopis within a nestedDo...Loop, execution continues with the nextLoopstatement wrapped around the current one. If, however, theDo...Loopis standalone, program execution continues with the first line of code after theLoopstatement.-
Exit For Exits a
For...Nextloop or aForEach...Nextstatement. If the currentFor...Nextis within a nestedFor...Nextloop, execution continues with the nextNextstatement wrapped around the current one. If, however, theFor...Nextloop is standalone, program execution continues with the first line of code after theNextstatement.-
Exit Function Exits the current function. Program execution is passed to the line following the call to the function.
-
Exit Property Exits the current property procedure. Program execution is passed to the line following the call to the property.
-
Exit Select Immediately exits a
SelectCaseconstruct. Execution continues with the statement immediately following theEndSelectstatement.-
Exit Sub Exits the current sub procedure. Program execution is passed to the line following the call to the procedure.
-
Exit Try Immediately exits a
Try...Catchblock. Program execution proceeds with theFinallyblock, if it is present, or with the statement following theEndTrystatement.-
Exit While ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access