# ineffective-break-in-switch

Disallow nonterminal switch breaks inside an enclosing loop

An unlabeled `break` inside a switch exits the switch even when the switch is nested in a loop.
Instead, you SHOULD label the enclosing loop when the break is intended to leave it.

The rule permits terminal case breaks used to prevent switch fallthrough.

- Category: suspicious
- Level: warning
- Fix: none
- Scope: module

## Reported

```ds title="main.ds"
function visit(values: int32[]): void {
    outer: for (const value of values) {
        switch (value) {
            default:
                if (value < 0) {
                    break;
                }
                value;
        }
    }
}
```

## Accepted

```ds title="main.ds"
function visit(values: int32[]): void {
    outer: for (const value of values) {
        switch (value) {
            default:
                if (value < 0) {
                    break outer;
                }
                value;
        }
    }
}
```

## Prior art

- [eslint-plugin-unicorn · no-break-in-nested-loop](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-break-in-nested-loop.md)

[language/linter/src/rules/suspicious/ineffective_break_in_switch.rs:6](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/suspicious/ineffective_break_in_switch.rs#L6)
