Occam provides for the conditional execution of code using the IF and CASE constructions. Each condition is

      IF                             CASE variable               
         boolean1                       value1
            process1                       process1
         boolean2                       value2
            process2                       process2
         booleanN                       valueN
            processN                       processN

The most important consideration when using an IF or CASE statement is that one of the conditions must be true. If all of the conditions are FALSE, then the IF or CASE statement is replaced with a STOP directive, terminating the program! If the possibility that no conditions are true is anticipated, then an IF statement may include as its final condition, TRUE, with the specified process as SKIP. If none of the other conditions are true, the final condition executes and performs no action.

Code may be executed repeatedly using the WHILE construction:

Note that the processes triggered by WHILE, IF, and CASE are simple primitive processes. To execute a block of code in response to one of these statements, a grouping constructor such as PAR or SEQ must be used. As an example, the following code constructs a two-element buffer (Burns, 1988, p. 26). Two WHILE statements containing sequential code are executed in parallel:

      CHAN OF INT in, out, middle:                               
        INT X:
        WHILE TRUE
            in ? X
            middle ! X
        INT X:
        WHILE TRUE
            middle ? X
            out ! X

Next: More Communications
Return to Index