EXIT                                                                      Statement

EXIT DO

EXIT FOR

EXIT FUNCTION

EXIT SUB

Description

EXIT terminates the execution of a block of code in a DO...LOOP, FOR...NEXT, FOR EACH...NEXT, FUNCTION, or SUB. When used to exit a loop, either DO...LOOP, FOR...NEXT, or FOR EACH...NEXT, execution continues with the first statement after the loop; if the loop is nested inside another loop, control is transferred to the loop outside the loop where the EXIT is encountered. When used to exit a FUNCTION or SUB procedure, execution continues with the first statement after the statement which called the procedure.

Example

REM EXIT Example

'EXIT terminates loops and procedures

DIM i

FOR i = 1 to 10

  IF i > 1 THEN

    EXIT FOR

  END IF

  PRINT "Attempting to do nothing"

  DoNothing

NEXT

PRINT "Done"

SUB DoNothing

  EXIT SUB

  PRINT "This statement is never executed"

END SUB

Output

Attempting to do nothing

Done

Related Items

FOR...NEXT, DO...LOOP, FUNCTION, PROPERTY, SUB