| 1 | (* while, tested after its body: rounds none, one and many; a condition |
| 2 | with and, or and a call; break; while true; and a check that fails in |
| 3 | the condition, told at its place in the source. *) |
| 4 | module WhileBottom; |
| 5 | import Out; |
| 6 | |
| 7 | var calls: INT; |
| 8 | |
| 9 | proc small(n: INT): BOOL; |
| 10 | begin |
| 11 | INC(calls); |
| 12 | return n < 3; |
| 13 | end; |
| 14 | |
| 15 | proc main*; |
| 16 | var i, n: INT; a: [4]INT; |
| 17 | begin |
| 18 | i := 5; |
| 19 | while i < 3 do INC(i); end; |
| 20 | Out.int(i); Out.ln; |
| 21 | i := 0; |
| 22 | while i < 1 do INC(i); end; |
| 23 | Out.int(i); Out.ln; |
| 24 | i := 0; |
| 25 | while (i < 10) and small(i) or (i = 7) do INC(i); end; |
| 26 | Out.int(i); Out.char(' '); Out.int(calls); Out.ln; |
| 27 | n := 0; |
| 28 | while true do |
| 29 | INC(n); |
| 30 | if n = 4 then break; end; |
| 31 | end; |
| 32 | Out.int(n); Out.ln; |
| 33 | i := 0; |
| 34 | while a[i] = 0 do INC(i); end; |
| 35 | end; |
| 36 | |
| 37 | end WhileBottom. |