Say we want to check two conditions, and we want to know which of those triggered the if. Given the following snippet, which option is better in terms of performance, neatness and software engineering, if we are to set the if within a loop
bool cond1 = false;
bool cond2 = false;
//set somehow cond1 or cond2 to true;
while(1){
// option 1
if(cond1){
//akcnowledge cond1
}
if(cond2){
//akcnowledge cond2
}
//option 2
if(cond1 || cond2){ // is there a way to know which condition was triggered without a nested if?
//acknowldege cond1
if(cond2){
// aknowldege cond2 instead of cond1
}
}
//unset bools,continue with loop, etc (doesn't matter for the sake of this question)
};
Aucun commentaire:
Enregistrer un commentaire