Back to table

While Loop

The following is a valid µOCCAM program that performs I/O. Simple test of while loops and Output. Program outputs value of y on each iteration.

Program file: /public/cs3/web/ipptests/while-test.io

INT x:
INT y:
SEQ 
  x:=5
  y:=0
  WHILE x > 0
    SEQ
      y:=y+x
      stdout ! y
      x:=x-1
      SKIP

When provided with this input: /public/cs3/web/ipptests/while-test.in



it should generate the following output: /public/cs3/web/ipptests/while-test.out

==> 5
==> 9
==> 12
==> 14
==> 15