Previous Page Next Page Contents

break -- terminate a loop or a case switch prematurely

Introduction

break terminates for, repeat, while loops, and case statements.

Call(s)


break _break()

Related Functions

case, for, next, quit, repeat, return, while

Details

Example 1

Loops are exited prematurely by break:

>> for i from 1 to 10 do
     print(i);
     if i = 2 then break end_if
   end_for
                                     1
      
                                     2
>> delete i:

Example 2

In a case statement, all commands starting with the first matching branch are executed:

>> x := 2:
   case x
    of 1 do print(1); x^2;
    of 2 do print(2); x^2;
    of 3 do print(3); x^2;
    otherwise print(UNKNOWN)
   end_case:
                                     2
      
                                     3
      
                                  UNKNOWN

In the next version, break ensures that only the statements in the matching branch are evaluated:

>> case x
    of 1 do print(1); x^2; break;
    of 2 do print(2); x^2; break;
    of 3 do print(3); x^2; break;
    otherwise print(UNKNOWN)
   end_case:
                                     2
>> delete x:

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000