Back to table

Whiles and Assigns

The following is a valid µOCCAM program. Instructions within while statement are executed in sequence. This program adds the numbers 1 to 10 together.

Program file: /public/cs3/web/ipptests/whiles_assigns.accept
INT a = 0: -- initialize a to 0
INT b = 0: -- initialize b to 0

WHILE (a <= 10)
  SEQ
    b := b + a -- sums the numbers 1 to 10

    -- final value of b would be 55

    a := a + 1    -- increment the value of a by one