Why do we need break after case statements?

Sometimes it is helpful to have multiple cases associated with the same code block, such as

case 'A':
case 'B':
case 'C':
    doSomething();
    break;

case 'D':
case 'E':
    doSomethingElse();
    break;

etc. Just an example.

In my experience, usually it is bad style to “fall through” and have multiple blocks of code execute for one case, but there may be uses for it in some situations.

Leave a Comment