# prefer-loop-condition

Prefer loop conditions over leading conditional breaks

A leading conditional `break` makes readers inspect the loop body to discover its primary continuation condition.
Instead, you SHOULD place the complemented condition in a `while` header when the test occurs before every iteration body.

- Category: style
- Level: warning
- Fix: suggestion
- Scope: module

## Reported

```ds title="main.ds"
declare function isDone(): boolean;
declare function work(): void;

loop {
    if (isDone()) {
        break;
    }
    work();
}
```

## Accepted

```ds title="main.ds"
declare function isDone(): boolean;
declare function work(): void;

while (!isDone()) {
    work();
}
```

## Prior art

- [eslint-plugin-unicorn · prefer-while-loop-condition](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-while-loop-condition.md)

[language/linter/src/rules/style/prefer_loop_condition.rs:8](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/style/prefer_loop_condition.rs#L8)
