Contents Previous Next Subchapters

Breaking Out Of For And While Loops
Syntax break
See Also while , for , goto , halt

Description
Transfers execution just past the end of the currently enclosing while of for loop.

Tutorial
If you enter
     x = 0
     while x < 4 begin
          x = x + 1
          if x == 3 then break
          print x
     end
O-Matrix will respond
     1
     2
If you enter
     for x = 1 to 4 begin
          if x == 3 then break
          print x
     end
O-Matrix will respond
     1
     2
The break statement aborts the inner most active while or for loop. If you enter
     j = 0
     for i = 1 to 2 begin
          while true begin
               j = j + 1
               break
          end
     end
     print j
O-Matrix will respond
     2
because the inner while loop is executed twice.