lundi 3 décembre 2018

Improve if statement logic

I have four bool values:

bool bValue1;
bool bValue2;
bool bValue3;
bool bValue4;

The acceptable values are:

         Scenario 1 | Scenario 2 | Scenario 3
bValue1: true       | true       | true
bValue2: true       | true       | false
bValue3: true       | true       | false
bValue4: true       | false      | false

So, for example, this scenario is not acceptable:

bValue1: false
bValue2: true
bValue3: true
bValue4: true

At the moment I have come up with this if statement to detect bad scenarios:

if(((bValue4 && (!bValue3 || !bValue2 || !bValue1)) ||
   ((bValue3 && (!bValue2 || !bValue1)) ||
   ((bValue2 && !bValue1) ||
   (!bValue1 && !bValue2 && !bValue3 && !bValue4))
{
    // There is some error
}

Can that statement logic be improved/simplified?

Aucun commentaire:

Enregistrer un commentaire