Back to table

Multiplying Input

The following is a valid µOCCAM program that performs I/O. This program reads in the input from stdin, tests it in a while loop and outputs the value each time the while loop is executed.

Program file: /public/cs3/web/ipptests/multiplying-input.io

-- program to test I/O
INT In.Put:
INT Out.Put:

stdin ? In.Put -- read in the input from stdin

WHILE (In.Put > 0) -- test the input value
  SEQ
    Out.Put := In.Put * 2  -- assign the variable outout to input 
    stdout ! Out.Put  -- give back to output to stdout
    In.Put := In.Put - 1  -- increment the input 
  -- end of while loop

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

5

it should generate the following output: /public/cs3/web/ipptests/multiplying-input.out

==>10
   8
   6
   4
   2