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?
}
break
s 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.