Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - Having AND and OR in the same condition, without parentheses [duplicate]

I know that using And (&&) and OR (||) in a condition statement shouldn't be used without parentheses.

So if you should use both conditions you should do (A && !B) || (C && D)

However, in some code I saw that they are not using Parentheses? What would happen then? I thought that didn't compile:

A && !B || C && D

I guess that it would resolve as with SUMS or MULTIPLICATIONS, I mean, resolve them as they are read:

(((A && !B) || C) && D)
like image 230
htafoya Avatar asked Oct 17 '25 23:10

htafoya


1 Answers

And (&&) has precedence over or (||) in the order of operations. So, this

A && !B || C && D

Is entirely equivalent to

(A && !B) || (C && D)
like image 159
elixenide Avatar answered Oct 20 '25 13:10

elixenide



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!