Forces immediate exit from the innermost REPEAT, FOREACH, UNTIL, or WHILE loop enclosing the BREAK command. Control will jump to the command following the innermost loop's END command. Any loop enclosing the innermost loop will continue as if the innermost loop had completed normally. |
The following program doesn't do anything more than illustrate the operation of the BREAK command. The inner WHILE loop would normally repeat until counter2 equals 99, but the BREAK forces it to exit when counter2 equals 5. If you run the program, you can inspect its output to see the effect of the BREAK. Alternatively, you can step through the program in the debugger. COPY 1 counter1 REPEAT 5 PRINT counter1 ADD 1 counter1 counter1 COPY 1 counter2 WHILE counter2 < 100 ADD 1 counter2 counter2 PRINT counter2 IF counter2 = 5 PRINT "Before the BREAK" BREAK 'Causes exit from the WHILE loop PRINT "After the BREAK" 'This PRINT command will never execute END PRINT "After IF command" 'Control jumps to here after BREAK END PRINT "After WHILE loop" END For a more practical example that uses the BREAK command, see the example in the FOREACH command's description. |