vendredi 15 février 2019

How to simplify compound negated logic

Lets say I have array of boolean values B[], or I am figuring out true/false using function. How can I simplify this code, it there are many values (maybe tens of them)? Here is pseudocode:

if(!B[0]){
    doTask1;
}
if(!B[0] && !B[1]){
    doTask1;
    doTask2;
}
if(!B[0] && !B[1] && !B[2]){
    doTask1;
    doTask2;
    doTask3;
}
...

Aucun commentaire:

Enregistrer un commentaire