# boolean help

• 05-09-2010
seekerofthetao
boolean help
hey...first time posting....i'm trying to get my programming skills back after 8 years of not using them. uphill battle, to say the least.

in any event, in going through the tutorials i hit a snag with the boolean operators AND, NOT, and OR.

i understand that they are processed in a specific (not, and, or) order, but within a complex statement how does it get processed?

the quiz example is !(1 && !(0 || 1))....what is the order of operations for this statement?

thanks for the help understanding this.
• 05-09-2010
NeonBlack
You figure it out the same way you do for arithmetic operators if you remember PEMA- Parenthesis, exponents, multiplication, addition. The boolean negation, AND and OR operators are analogous to the arithmetic negation, multiplication and addition operators.
Parenthesis are evaluated first, followed by negation, and and or.
So the expression you posted is analogous to
-(1 * -(0+1))
• 05-10-2010
seekerofthetao
thank you very much. i had a feeling that it was easier than i was making it out to be.
• 05-10-2010
Brafil
But of course the compiler will only evaluate the parantheses if the first expression turns out to be true. It goes left-to-right and stops as soon as the result is known (for example if it encounters '0 && 1' it evaluates 0, which turns out to be false, and stops cuz the expression has to be false, too)