BREAK

The BREAK statement provides a convenient way to immediately exit from a loop (FOR, FOREACH, WHILE, REPEAT), CASE, or SWITCH statement without resorting to GOTO statements.

Syntax

BREAK

Examples

This example exits the enclosing WHILE loop when the value of i hits 5.

PRO count
I = 0
PRINT, 'Initial value: ', i
WHILE (1) DO BEGIN
   i = i + 1
   IF (i eq 5) THEN BREAK
   PRINT, 'Loop value: ', i
ENDWHILE
PRINT, 'END VALUE: ', I
END
count

Version History

5.4

Introduced

See Also

BEGIN...END, CASE, CONTINUE, FOR, FOREACH, GOTO, IF...THEN...ELSE, REPEAT...UNTIL, SWITCH, WHILE...DO, IDL Programming