Skip to main content

useWhile (since v0.7.0)

This rule is recommended by Rome.

Enforce the use of while loops instead of for loops when the initializer and update expressions are not needed

Examples

Invalid

for (; x.running;) {
x.step();
}
error[js/useWhile]: Use while loops instead of for loops.
   js/useWhile.js:1:1
  
1  for (; x.running;) {
   ^^^^^^^^^^^^^^^^^^

Suggested fix: Use a while loop
    | @@ -1,3 +1,3 @@
0   | - for (; x.running;) {
  0 | + while (x.running) {
1 1 |       x.step();
2 2 |   }