Is it considered bad coding to put a break in the default part of a switch statement? A book I was reading said that it was optional but the teacher counted off for using it.
Best practice is to always use a break
unless you mean for control to flow into another case, even at the end of the switch.
It depends if you have it at the start or the end of the switch statement. If there are other case
s after the default
then you probably do want a break
there unless you really want to fall through.
switch (a)
{
case 0:
default:
printf("Default\n");
break;
case 1:
printf("1\n");
break;
case 2:
printf("2\n");
break;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With