| Introduction | MTB Statements | File System | Compiler | Applications | Reference Guide | Index |
| Language Structure | Data Division | I/O Format Division | Procedure Division | Mnemonics |
| Syntax: | BREAK |
| Discussion: |
The BREAK statement stops execution of the conditional statement
block within a FOR/NEXT structure, a
DO/LOOP structure, or a
SELECT/CASE structure. The BREAK statement
passes control to
the statement following the final statement in the structure (the
NEXT statement, LOOP
statement, or ENDSELECT statement,
respectively).
The BREAK statement must occur between a FOR and NEXT statement, between a DO and LOOP statement, or within a CASE block. If a BREAK statement occurs within an IF/THEN or IF/THEN/ELSE structure, the IF structure must itself be within a FOR/NEXT loop, DO/LOOP structure, or CASE block, and the BREAK statement refers to the FOR, DO, or CASE structure, accordingly. There can be multiple BREAK statements within a given FOR/NEXT or DO/LOOP structure. |
| Example 1: |
FOR I=1 TO 10 ! Start the loop . IF A=I THEN BREAK ! If A=I jump to end of loop . NEXT I ! Increment I and loop back HERE: ! The BREAK statement jumps to this label |
| Example 2: |
DO WHILE I LE 10 ! Start the loop . IF A=I [THEN] BREAK ! If A=I jump to end of loop . LOOP ! Loop back HERE: ! The BREAK statement jumps to this label |