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
-
ExitDo 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.-
ExitFor 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.-
ExitFunction Exits the current function. Program execution is passed to the line following the call to the function.
-
ExitProperty Exits the current property procedure. Program execution is passed to the line following the call to the property.
-
ExitSelect Immediately exits a
SelectCaseconstruct. Execution continues with the statement immediately following theEndSelectstatement.-
ExitSub Exits the current sub procedure. Program execution is passed to the line following the call to the procedure.
-
ExitTry Immediately exits a
Try...Catchblock. Program execution proceeds with theFinallyblock, if it is present, or with the statement following theEndTrystatement.-
ExitWhile ...
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