if(var == something) {
A();
B();
} else if(var == something_else) {
A();
B();
C();
} else {
assert(false);
}
How can i avoid duplicate code of calling A() and B() in both if
cases. Should i use switch case like,
switch(var) {
case something:
case something_else:
A();
B();
break;
}
if (var == something_else)
C():
What is the better solution? Is there any performance penalty in switch
vs if else
?