Unused Control Flow Label

ID

swift.unused_control_flow_label

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Swift

Tags

dead-code, reliability

Description

Reports a labelled loop or switch whose label is never targeted by an inner break <label> or continue <label>. The label adds no information at the call site and is dead weight.

outer: for row in rows {                       // FLAW
    for cell in row {
        if cell.isEmpty { break }              // unlabelled — refers to inner loop
    }
}

outer: for row in rows {                       // OK
    for cell in row {
        if cell.isEmpty { break outer }
    }
}

Rationale

Labels exist solely to be targets for break and continue. A label that no inner statement references is either a leftover from a refactor that removed the inner break or a planned-but-never-used optimisation. Either way it slows down readers, who scan for the matching break <label> and find none.

Remediation

Drop the label entirely:

for row in rows {
    for cell in row {
        if cell.isEmpty { break }
    }
}

Or add the inner break <label> / continue <label> you actually intended.