Search code examples
javaboolean-logicboolean-operations

How can I write a if statement with multiple conditions?


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.


Solution

  • (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
    }