Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))

Exit Statement

Syntax

Exit Do Exit For Exit Function Exit Property Exit Select Exit Sub Exit Try Exit While

Description

The various Exit statements prematurely exit a block of code.

Usage at a Glance

The Exit statement is used as follows:

Statement

Description

Exit Do

Exits a Do...Loop statement. If the statement appears in nested Do...Loop loops, only the innermost loop is exited. Program execution continues with the first line of code after the exited loop.

Exit For

Exits a For...Next or a For Each...Next loop. If the statement appears in nested For loops of any type, only the innermost loop is exited. Program execution continues with the first line of code after the exited loop.

Exit Function

Exits the current function and returns control to the calling procedure.

Exit Property

Exits the current property (either Get or Set) and returns control to the calling procedure.

Exit Select

Exits a Select Case construct. If the statement appears in nested Select Case blocks, only the innermost block is exited. Program execution continues with the first line of code after the exited block.

Exit Sub

Exits the current sub procedure and returns control to the calling procedure.

Exit Try

Exits a try...Catch block. Program execution proceeds with the Finally block if it is present or, otherwise, with the statement following the End Try statement.

Exit While

Exits a While...End While statement. If the statement appears in nested While...End

While loops, only the innermost loop is exited. Program execution continues with the first line of code after the exited loop.

See Also

Continue Statement, End Statement

Категории