I am a bit puzzled on whenever or not to include break after the last case, often default.
switch (type) {
case 'product':
// Do behavior
break;
default:
// Do default behavior
break; // Is it considered to be needed?
}
breaks sole purpose is in my understanding to stop the code from running through the rest of the switch-case.
Is it then considered more logical to have a break last due to consistency or skip having it due to the break applying no functional use whatsoever? Both are logical in different ways in my opinion.
This could to a certain degree be compared with ending a .php file with ?>. I never end with ?> mostly due to the risk of outputting blank spaces, but one could argue that it would be the logical thing to end the file with.
breaklast case aswell :) – Robin Castlin Jun 17 '13 at 11:50break(or other control-flow statement that exits thecase) is technically needed after the last alternative. – dan04 Jun 17 '13 at 15:43switchfall-through in existing languages and wanted to prevent them. The rules C# imposes pretty much match the recommendations from my answer. – tdammers Jun 17 '13 at 20:10breakas a NO-OP instead of generating ajmpto the next instruction, correct? – Nathan Osman Jul 15 '13 at 19:06