lundi 13 juin 2016

Conditional supercede all others for if complex

I have an if statement something like the below:

if (A ... B ... C) {
    //X
} else {
    //Y
}

A, B, and C are conditions that depending on prior variables or conditions can be true or false. I'm trying to wrap my head around using the right logical operators to get this desired result:

X happens if
    A is true but B is false
Y happens if
    B is true, or
    C is true, or
    A is false and B is false
    If C is true, it doesn't matter truthiness of A or B, Y must happen

I have figured out how to use A and B but not C:

if (A ^ B) {
    //X
} else {
    //Y
}

For all instances, if B is true, A is always true. This check is done on multiple pages and pages where B is true, Y always happens. The problem I'm having is adding C to the mix: it should supercede everything else.

Aucun commentaire:

Enregistrer un commentaire