Exit Statement

Describe

Syntax

Exit { Do | For | Function | Method | Property | Sub | While }

Parts

Exit Do
Immediately exits the Do...Loop loop in which it appears. Execution continues with the statement following the Loop clause.
Exit For
Immediately exits the For or For Each loop in which it appears. Execution continues with the statement following the End For clause.
Exit Function
Immediately exits the Function procedure in which it appears. Execution continues with the statement that called the procedure, if the expression needs further evaluation; or the following statement otherwise.
Exit Method
Immediately exits the Method procedure in which it appears. Execution continues with the statement that called the procedure, if the expression needs further evaluation; or the following statement otherwise.
Exit Property
Describe
Exit Sub
Immediately exits the Sub procedure in which it appears. Execution continues with the statement following the statement that called the procedure.
Exit While
Immediately exits the While loop in which it appears. Execution continues with the statement following the End While clause.

Details

When Exit is used in nested loops of the same type (e.g. two For loops), Exit exits the innermost loop and transfers control to the next higher level of nesting.

Examples

See also