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.
First, we solve any operations inside of parentheses or brackets. Second, we solve any exponents. Third, we solve all multiplication and division from left to right. Fourth, we solve all addition and subtraction from left to right.
Order of operations tells you to perform multiplication and division first, working from left to right, before doing addition and subtraction. Continue to perform multiplication and division from left to right. Next, add and subtract from left to right.
Applying the Order of Operations (PEMDAS) The order of operations says that operations must be done in the following order: parentheses, exponents, multiplication, division, addition, and subtraction.
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)
See: https://en.wikipedia.org/wiki/Order_of_operations
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With