Lets say I have a function that takes an argument, does some action based on the value of that argument and returns false if there is no action for that value. (pseudo-code):
bool executeSomeAction(someValue) {
switch (someValue) {
case shouldDoAction1:
action1();
break;
case shouldDoAction2:
action2();
break;
default:
return false;
}
return true;
}
Is it bad practise to write it like this:
bool executeSomeAction(someValue) {
switch (someValue) {
case shouldDoAction1:
action1();
return true;
case shouldDoAction2:
action2();
return true;
default:
return false;
}
}
Edit: I don't see how this is a duplicate of the linked question, I'm asking about the best practise of writing a function with a single switch statement, I'm not at all asking about using a single or multiple return statements.