Computer Studies‎ > ‎Turing‎ > ‎Turing Tutorial‎ > ‎

Turing 023 — Counters & Loops (incomplete)

Counters are integer variables used to keep track of how often a programming event occurs. For example, a counter may be used to keep track of how many times the user has tried to win a game.
A loop is a segment of program code that is repeated until a specific event occurs. Loops are often used in conjunction with counters, as the following code demonstrates:
var i : int
i := 1
  put i
  i := i + 1
  exit when i = 10
end loop


Modify the example program so it prints all even numbers from 100 to 120 (inclusive).
Save as "023.t".

Additional Notes

In the "exit when" statements used above, we always used the "=" comparison operator. Occasionally we may wish to use other operators such as the following:
< ... less than
... greater than
not= ... not equal to
<= ... less than or equal to
>= ... greater than or equal to