1 # Disallow unmodified conditions of loops (no-unmodified-loop-condition)
3 Variables in a loop condition often are modified in the loop.
4 If not, it's possibly a mistake.
21 This rule finds references which are inside of loop conditions, then checks the
22 variables of those references are modified in the loop.
24 If a reference is inside of a binary expression or a ternary expression, this rule checks the result of
25 the expression instead.
26 If a reference is inside of a dynamic expression (e.g. `CallExpression`,
27 `YieldExpression`, ...), this rule ignores it.
29 Examples of **incorrect** code for this rule:
32 /*eslint no-unmodified-loop-condition: "error"*/
41 for (var j = 0; j < items.length; ++i) {
42 doSomething(items[j]);
45 while (node !== root) {
50 Examples of **correct** code for this rule:
53 /*eslint no-unmodified-loop-condition: "error"*/
60 for (var j = 0; j < items.length; ++j) {
61 doSomething(items[j]);
64 // OK, the result of this binary expression is changed in this loop.
65 while (node !== root) {
70 // OK, the result of this ternary expression is changed in this loop.
71 while (node ? A : B) {
76 // A property might be a getter which has side effect...
77 // Or "doSomething" can modify "obj.foo".
82 // A function call can return various values.
90 If you don't want to notified about references inside of loop conditions, then it's safe to disable this rule.