...
The break
statement at the end of the final case in a switch
statement may be omitted. By convention, this is the default
label. The break
statement serves to transfer control to the end of the switch
block. Fall-through behavior also causes control to arrive at the end of the switch
block. Consequently, control transfers to the statements following the switch
block without regard to the presence or absence of the break
statement. Nevertheless, the final case in a switch
statement should end with a break
statement in accordance with good programming style (see [Rogue 2000]).
Exceptions
MSC53:EX0: When multiple cases require execution of identical code, then break
statements may be omitted from all cases except the last one. Similarly, when processing for one case is a proper prefix of processing for one or more other cases, the break statement may be omitted from the prefix case. This should be clearly indicated with a comment. For example:
Code Block | ||
---|---|---|
| ||
int card = 11; int value; // Cases 11,12,13 fall through to the same case switch (card) { // MSC13-JMSC53:EX2EX0: processing for this case requires a prefix // of the actions for the following three case 10: do_something(card); // intentional fall-through // MSC13-JMSC53:EX2EX0: these three cases are treated identically case 11: // break not required case 12: // break not required case 13: value = 10; break; // break required default: // Handle Error Condition } |
...