Just a reminder: while the most suggested case is the best solution, note that if you don't close with a brake;
your case:
, it will continue executing in the next case.
Then, while it's still best pratice to break your cases, you could still adopt a solution similar to the following:
switch (orderType) {
case 3:
someMethod1();
case 2:
someMethod2();
break;
case 1:
someMethod1();
break;
default:
break;
}
Note that "avoiding breaks" solution can't completely cover OP necessities, because writing:
case 3:
case 1:
someMethod1();
case 2:
someMethod2();
default:
break;
or:
case 3:
case 1:
someMethod1();
break;
case 2:
someMethod2();
break;
default:
break;
would make case: 3
be the same than case: 1
, making them execute both methods in first code, or a single method in the second code.