My OCD makes me add "break" when writing case statements, even if they will not be executed. Consider the following code example:
switch(option) { case 1: a = 1; b = 7; break; case 2: a = 2; b = 4; return (-1); break; default: a = -1; break; }
My two questions are: For "case 2:", I don't really need the break, but is it a good idea to have it there anyway? For "default:". Is it purely OCD, or is there any real reason to have the break here?
You don't need either break, but there's no harm in having them. In my opinion, keeping your code structured is worth having a couple of extraneous statements.
1.4m articles
1.4m replys
5 comments
57.0k users