Both of these things may be done with short-circuit control forms such as:
if NUMBER /= 0 and then TOTAL/NUMBER > MEDIAN then ... end if; |
Clearly it would not be proper to express this condition as a boolean expression using the and operator, since an exception would be raised if NUMBER were zero and the second operand were evaluated. Similarly, short-circuit disjunctions can be expressed with or else clauses as in the following example:
exit when NEXT = null or else NEXT.AGE = 0;
In this case the condition following or else will only be evaluated if the previous condition is not satisfied.
In Algol 60 one can achieve the effect of short-circuit evaluation only by use of conditional expressions, since complete evaluation is performed otherwise. This often leads to constructs that are tedious to follow:
if(if NUMBER = 0 then TRUE else TOTAL/NUMBER > MEDIAN) then ...
Several languages do not define how boolean conditions are to be evaluated. As a consequence programs based on short-circuit evaluation will not be portable. This clearly illustrates the need to separate boolean operators from short-circuit control forms.