Reputation: 7577
Is this good practise ... ie, grouping the default case with another?
switch ($cond){
case 1:
...;
break;
case 2:
...;
break;
case 3:
default:
...;
break;
}
Upvotes: 6
Views: 222
Reputation: 16431
It makes perfect sense to do it that way.
Also, @Ian is correct, but in a limited scope. If you wanted additional functionality applied to case 3
you would leave it the way it is. As long as you don't break
, it will go on to the next case
.
Upvotes: 3
Reputation: 11056
It kind of makes case 3
redundant though, so I'd remove it and just leave it as default
Upvotes: 1