Reputation: 378
I am trying to write a if statement where if a is true and if either (b or c) is true then do something.
I've written this but I am not sure if the logic of it is correct.
if (critStatus == false && badStatus == true || pmBadStatus == true) {
//do something
}
Basically if critStatus is false && if badstatus or pmbadstatus is true then it should do something.
Upvotes: 0
Views: 1018
Reputation: 25
if (critStatus == false && (badStatus == true || pmBadStatus == true)) {
//do something
}
all you need is parenthesis. before the parenthesis the statement was:
if ((a = true and b = true) OR c = true){
Upvotes: 0
Reputation: 2296
&&
has higher precedence than ||
, so you have to write your condition like this:
if (critStatus == false && (badStatus == true || pmBadStatus == true))
See the Java precedence rules here.
Upvotes: 1
Reputation: 48307
(A&&B)||C or A&&(B||C) are not the same evaluated, the order will be depending where are the parenthesis.
You mean
if (!critStatus && (badStatus || pmBadStatus)) {
//do something
}
Upvotes: 1