lundi 13 janvier 2020

Simplify 4 if/else checks on two booleans

I have a situation like this in my code:

bool a, b, result;
... // a and b are set
if(!a &&! b)
    result = functionOne() ;
else if(!a && b)
    result = functionTwo();
else if(a &&! b)
    result = functionThree();
else
    result = functionFour();

Is there any way to simplify/shorten this code? Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire