What is the equivalent of this statement?
if(cond1 AND cond2 AND cond3 OR cond4 AND cond5 AND cond6)
Is it
if((cond1 AND cond2 AND cond3) OR (cond4 AND cond5 AND cond6))
Or
if(cond1 AND cond2 AND (cond3 OR cond4) AND cond5 AND cond6)
Or
if(((cond1 AND cond2 AND cond3) OR cond4) AND cond5 AND cond6)
ect...
This has been something that I've always been scared approaching, to which I just surround the conditions in parenthesis ( )
. It would be great if my mind could be settled.
A good way to remember this is to think of it mathematically.
AND
as *
(multiply)OR
as +
(addition)TRUE
as 1
FALSE
as 0
So thinking of it as simple math you get this:
0 * 0 = 0
1 * 0 = 0
1 * 1 = 1
0 + 0 = 0
1 + 0 = 1
1 + 1 = 1
Only thing that may be a tiny bit confusing is 1 + 1 = 1
, but a bit can't go above 1
. But it makes sense if you think of 1
as any non-zero number.
So with this in mind you can then apply this logic:
if(cond1 AND cond2 AND cond3 OR cond4 AND cond5 AND cond6)
Becomes:
if(cond1 * cond2 * cond3 + cond4 * cond5 * cond6)