Skip to content

Files

Latest commit

 

History

History
75 lines (52 loc) · 809 Bytes

unneeded_break_in_switch.md

File metadata and controls

75 lines (52 loc) · 809 Bytes

Pattern: Unneeded break in switch

Issue: -

Description

Avoid using unneeded break statements.

Examples of correct code:

switch foo {
case .bar:
    break
}


switch foo {
default:
    break
}


switch foo {
case .bar:
    for i in [0, 1, 2] { break }
}


switch foo {
case .bar:
    if true { break }
}


switch foo {
case .bar:
    something()
}

Examples of incorrect code:

switch foo {
case .bar:
    something()
    break
}


switch foo {
case .bar:
    something()
    break // comment
}


switch foo {
default:
    something()
    break
}


switch foo {
case .foo, .foo2 where condition:
    something()
    break
}

Further Reading