menu

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.

Reported

1declare function isDone(): boolean;2declare function work(): void;3 4loop {5    if (isDone()) {6        break;7    }8    work();9}

Accepted

1declare function isDone(): boolean;2declare function work(): void;3 4while (!isDone()) {5    work();6}