booleanpascal

How to test if exactly one condition is true?


If I have a set of boolean variables in Pascal, how can I test if exactly one of them is True?


Solution

  • In Pascal you can do this:

    if Integer(a) + Integer(b) + Integer(c) = Integer(true) then
        writeln("exactly one is true");
    

    It's important to compare to Integer(true), since it could be different values in different versions of Pascal.