mercredi 1 février 2017

Refactor repeated if statements

Is there a way to make this not have to check conditions multiple times

if(a || b || c){
    print('header');
    if(a){do_something_a();}
    if(b){do_something_b();}
    if(c){do_something_c();}
}else{
    print('alt-header');
}

I do not like the idea of needing to or all of the conditions before checking each one individually but I am not sure there is a better approach

Aucun commentaire:

Enregistrer un commentaire