Back to table

While Loops and Output

The following is a valid µOCCAM program. This program tests the while loops capability of handling assignments and outputting them. The program calculates 8+..+1 and outputs the result at every stage. It then outputs the value of y - x = 36-10 = 26.

Program file: /public/cs3/web/ipptests/while-op.accept
SEQ
  INT x := 0
  INT y := 10
  WHILE x < 8
    SEQ
      x := x + 1
      y := y + x
      stdout ! y
  x := y - x
  stdout ! x