raz / conform / run / ForEdges.raz

42 lines · 1.8 KiB · raw · history · last change f627f570

1module ForEdges;
2
3(* for loops at their edges: the body moving the variable past the limit
4 and back, the value left after the loop, steps that would wrap the
5 type, a limit changed in the body, and enumerations. *)
6import Out;
7
8type Day = (mon, tue, wed, thu, fri, sat, sun);
9
10proc show(n: I64); begin Out.int(n); Out.str(" "); end;
11
12proc main*;
13var i, b, n: INT; u: U8; k: I8; d: Day; w: U64;
14begin
15 for i := 1 to 10 do show(i); if i = 3 then i := 20; end; end; show(i); Out.ln;
16 for i := 1 to 10 do show(i); if i = 2 then i := 7; end; end; show(i); Out.ln;
17 for i := 1 to 10 by 4 do show(i); end; show(i); Out.ln;
18 for i := 1 to 10 by 3 do show(i); if i = 4 then i := 9; end; end; show(i); Out.ln;
19 for i := 10 to 1 by -1 do show(i); if i = 8 then i := -5; end; end; show(i); Out.ln;
20 for i := 10 to 1 by -4 do show(i); end; show(i); Out.ln;
21 for i := 5 to 1 do show(i); end; show(i); Out.ln;
22 b := 3;
23 for i := 1 to b do show(i); b := 10; end; show(i); Out.ln;
24 n := 0;
25 for u := 250 to 255 do INC(n); end; show(n); show(I64(u)); Out.ln;
26 n := 0;
27 for u := 5 to 0 by -1 do INC(n); end; show(n); show(I64(u)); Out.ln;
28 n := 0;
29 for u := 200 to 255 do INC(n); if u = 210 then u := 255; end; end; show(n); show(I64(u)); Out.ln;
30 n := 0;
31 for k := -128 to 127 by 50 do INC(n); end; show(n); show(I64(k)); Out.ln;
32 n := 0;
33 for k := 120 to 127 do INC(n); if k = 125 then k := 127; end; end; show(n); show(I64(k)); Out.ln;
34 n := 0;
35 for w := 0FFFFFFFFFFFFFFF0H to 0FFFFFFFFFFFFFFFFH by 5 do INC(n); end; show(n); Out.ln;
36 for d := mon to sun by 2 do show(I64(d)); end; show(I64(d)); Out.ln;
37 for d := sun to mon by -1 do if d = fri then d := tue; end; show(I64(d)); end; Out.ln;
38 n := 0;
39 for i := 0 to 9 do if i = 5 then break; end; INC(n); end; show(n); show(i); Out.ln;
40end;
41
42end ForEdges.