Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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
bgColor#CCCCFF
int card = 11;
int value;

// Cases 11,12,13 fall through to the same case 
switch (card) {
  // MSC13-J:EX2: processing for this case requires a prefix
  //              of the actions for the following three
  case 10:
    do_something(card);
    // intentional fall-through
  // MSC13-J:EX2: 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 
}

...