raz / conform / run / Breaks.raz

22 lines · 799 B · raw · history · last change 11681e72

1module Breaks;
2
3(* Leaving loops by break: on conditions of and and or, before elsif
4 and else, and with a deferred statement to run on the way out. *)
5import Out;
6var log: INT;
7proc note; begin INC(log); end;
8proc main*;
9var i, s: INT; b: BOOL;
10begin
11 for i := 0 to 100 do if i > 3 and i # 4 then break; end; s := s + i; end;
12 Out.int(s); Out.ln; (* 0+1+2+3+4 = 10 *)
13 s := 0;
14 for i := 0 to 100 do if i = 7 or i * i > 30 then break; elsif i = 2 then s := s + 100; else s := s + i; end; end;
15 Out.int(s); Out.ln; (* 0+1+100+3+4+5 = 113 *)
16 s := 0; i := 0;
17 while true do b := i = 5; if b then break; end; INC(i); end;
18 Out.int(i); Out.ln; (* 5 *)
19 for i := 0 to 3 do defer note; if i = 2 then break; end; end;
20 Out.int(log); Out.ln; (* 3 *)
21end;
22end Breaks.