Skip to content

Files

Latest commit

 

History

History
35 lines (26 loc) · 705 Bytes

no-switch-case-fall-through.md

File metadata and controls

35 lines (26 loc) · 705 Bytes

Pattern: Fall-through in switch statement

Issue: -

Description

Fall-through in switch statements is often unintentional and a bug.

For example, the following is not allowed:

switch(foo) {
    case 1:
        someFunc(foo);
    case 2:
        someOtherFunc(foo);
}

However, fall through is allowed when case statements are consecutive or a magic /* falls through */ comment is present. The following is valid:

switch(foo) {
    case 1:
        someFunc(foo);
        /* falls through */
    case 2:
    case 3:
        someOtherFunc(foo);
}

Further Reading