Skip to content

noUnmodifiedLoopCondition (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noUnmodifiedLoopCondition": "error"
}
}
}
}

Disallow loop conditions whose variables are never modified in the loop.

A variable in a loop condition usually changes during the loop. If it does not, the loop may never terminate or may not run as intended.

Binary and conditional expressions are checked as a group. The condition is considered modified when any variable in the group changes in the loop. References inside dynamic expressions, such as function calls and property accesses, are ignored because their values may change without a local assignment. A binary or conditional expression containing a dynamic expression is ignored as a group.

let node = getNode();
while (node) {
process(node);
}
code-block.js:2:8 lint/nursery/noUnmodifiedLoopCondition ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This loop condition variable is not modified in the loop.

1 │ let node = getNode();
> 2 │ while (node) {
^^^^
3 │ process(node);
4 │ }

An unchanged condition can make the loop run forever or prevent it from behaving as intended.

Update the variable during each iteration, or use a condition whose value can change.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

for (let index = 0; index < 5;) {
process(index);
}
code-block.js:1:21 lint/nursery/noUnmodifiedLoopCondition ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This loop condition variable is not modified in the loop.

> 1 │ for (let index = 0; index < 5;) {
^^^^^
2 │ process(index);
3 │ }

An unchanged condition can make the loop run forever or prevent it from behaving as intended.

Update the variable during each iteration, or use a condition whose value can change.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

let node = getNode();
while (node) {
process(node);
node = node.parent;
}
for (let index = 0; index < items.length; index++) {
process(items[index]);
}
while (object.ready) {
process(object);
}