There are a few special infix operations that take two Booleans and result in a Boolean: "and", "or", and "xor" (exclusive-or), with their usual meanings. The value of `True and False' is False, while the value of `True or False' is True. `Exclusive or' is true if either of two conditions, but not both, is true.
There is also the prefix operation ``not''. If a boolean variable A has the value True, `not A' has the value False.
Although you can probably guess what the values of any combination of values is, here they are officially:
--- When ---+------------------- Then ----------------- A B | (A and B) (A or B) (A xor B) (not A) True True | True True False False True False | False True True False False True | False True True True False False | False False False True
Normally Ada will evaluate these expressions in whatever order is most efficient for the machine. If it's important to evaluate them in a certain order and to stop evaluating them when the answer is known, there are versions of `and' and `or' that are called `short-circuit operations'. These operations will execute strictly left-to-right and will not execute anything if they don't have to. C's && and || operations work this way. The short-circuit version of `and' is `and then'; the short-circuit version of `or' is `or else'. For example, if you want to do something if K isn't zero and 1.0/K is more than B, but you realize that the latter test must be done after the former:
if K /= 0 and then 1.0/Float(K) > B then ...
Which of the following is True?
![]() |
![]() |
![]() |
---|
David A. Wheeler (dwheeler@ida.org)