EWD249 - 23
So far, so good.
The program, however, is written under the assumption that "reduce r modulo dd" is not a primitive action, while "decrease r by dd" is. Viewing all possible happenings during "reduce r modulo dd" it becomes then relevant to distinguish that in some cases "decrease r by dd" takes place, while in the other cases r remains unchanged. By writing
"if dd ≤ r do decrease r by dd"
we have represented that at the given level of detail the action "reduce r modulo dd" can take one of two mutually exclusive forms and we have also given the criterion on account of which the choice between them is made. If we regard "if dd ≤ r do" as a conditional clause attached to "decrease r by dd" it is natural that the conditional clause is placed in front of the conditioned statement. (In this sense the alternative clause
"if condition then statement 1 else statement 2"
is "over-ordered" with respect to "statement 1" and "statement 2": they are just two alternatives that cannot be expressed simultaneously on a linear medium.)
The alternative clause has been generalized by C.A.R.Hoare whose "case-of" construction provides a choice between more than two possibilities. In flowchart form they can be represented as follows.
|
v
+- - - - - - - - - - -+
| +---------+ |
| | ? | |
| +---------+ |
| | | |
| +-----+ | |
| | S1 | | |
| +-----+ | |
| \ | |
| \ | |
| \ / |
| \ / |
+- - - - -\- -/ - - - +
\ /
v
if ? do S1
|
v
+- - - - - - - - - - - -+
| +---------+ |
| | ? | |
| +---------+ |
| | | |
| +-----+ +-----+ |
| | S1 | | S2 | |
| +-----+ +-----+ |
| \ / |
| \ / |
+- - - -\- - / - - - - -+
\ /
v
if ? then S1 else S2