In essence, if either switch 1 or switch 2 (or both) are on and error flag is false, then I want a certain action to take place (print "Condition met" in the example above). Changing the switch variables achieves the anticipated effect however whether Err equals true or false seems to have no effect on the algorithm.
I usually run into trouble mixing my 'AND's and 'OR's.
Can someone explain the flaw in my logic?
In this table you can see the && is executed befor the ||
Which sort-of makes sense because && is a boolean equivalent of multiply, and || is a boolean equivalent of add.
(0*1 = 0, 0+1 = 1)
But it's better to just use extra parens than to count on everyone remembering the correct order of execution!
The MISRA-C and MISRA-C++ rules used by many developers of critical embedded software forbid expressions such as "sw1 == 1 || sw2 == 1 && Err == false" (without extra parentheses) for exactly this reason.