menu

loop-single-iteration

Disallow loops whose control flow cannot reach another iteration

A loop whose body always exits or diverges cannot reach a second iteration and obscures its actual control flow. Instead, you SHOULD use a conditional for optional execution or state an unconditional transfer directly.

Reported

1declare function ready(): boolean;2declare function process(): void;3 4while (ready()) {5    process();6    break;7}

Accepted

1declare function ready(): boolean;2declare function process(): void;3 4if (ready()) {5    process();6}