EXIT statement  

Purpose

Transfer program execution out of a block structure.

Syntax

EXIT FASTPROC       ' FastProc / End FastProc

EXIT FOR            ' For / Next Loop

EXIT FUNCTION       ' Function / End Function

EXIT IF             ' If / End If

EXIT DO             ' Do / Loop or While / Wend

EXIT LOOP           ' Do / Loop or While / Wend

EXIT MACRO          ' Macro / End Macro

EXIT METHOD         ' Method / End Method

EXIT PROPERTY       ' Property / End Property

EXIT SELECT         ' Select / End Select

EXIT SUB            ' Sub / End Sub

EXIT TRY            ' Try / End Try

EXIT [,ITERATE]     ' Exit one loop and immediately iterate another

EXIT [,EXIT...]     ' The nearest enclosing block structure

Remarks

The EXIT statement allows you to leave a code section block immediately.  Using EXIT by itself will leave the most recently executed structure, but not an outer block.  EXIT, EXIT will leave two block structures, and EXIT, EXIT, EXIT will leave three levels.  For example:

FOR ix = 1 TO 10

  DO UNTIL x > 10

    EXIT FOR' will exit from the DO LOOP

  LOOP

NEXT

EXIT is preferred over GOTO for this purpose.  If you want to exit a structure other than the one most recently executed, you may include the type of structure, or you can use multiple EXIT's.  The following two examples are functionally identical:

FOR ix = 1 TO 10

  DO UNTIL x > 10

    EXIT FOR  ' will exit DO and FOR NEXT loop

  LOOP

NEXT

 

FOR ix = 1 TO 10

  DO UNTIL x > 10

    EXIT, EXIT  ' will exit DO and FOR NEXT loop

  LOOP

NEXT

You can also exit one loop and immediately iterate another:

FOR x = 1 TO 10

  DO

    EXIT, ITERATE

  LOOP

NEXT

See also

DO/LOOP, FASTPROC, FOR EACH/NEXT, FOR/NEXT, FUNCTION/END FUNCTION, IF/END IF blockITERATE, MACRO/END MACRO, METHOD, PROPERTY, SELECT, SUB/END SUB, TRY/END TRY, WHILE/WEND