dimanche 6 septembre 2020

How to avoid coding same code twice in (if, if else) statement, when the code has to run if one is true?

Consider this pseudo code:

if(p){
 foo()
 bar1()
}
if else(q){
 foo()
 bar2()
}

Is there a way of avoiding writing the call for function foo() twice? I could write:

if(p||q){
 foo()
}
...

But is that the only solution?

Aucun commentaire:

Enregistrer un commentaire