'flags' is not modified in this loop.
10637
10638 // parse flags
10639 let leftJustify = false; let positivePrefix = ''; let zeroPad = false; let prefixBaseX = false; let htmlSpace = false; let thousandSeparation = false
10640 for (let j = 0; flags && j < flags.length; j++) {10641 switch (flags.charAt(j)) {
10642 case ' ': positivePrefix = ' '; break
10643 case '+': positivePrefix = '+'; break
Description
Variables in a loop condition often are modified in the loop. If not, it's possibly a mistake.
Bad Practice
while (node) {
doSomething(node);
}
node = other;
for (var j = 0; j < items.length; ++i) {
doSomething(items[j]);
}
while (node !== root) {
doSomething(node);
}
Recommended
while (node) {
doSomething(node);
node = node.parent;
}
for (var j = 0; j < items.length; ++j) {
doSomething(items[j]);
}
// OK, the result of this binary expression is changed in this loop.
while (node !== root) {
doSomething(node);
node = node.parent;
}
// OK, the result of this ternary expression is changed in this loop.
while (node ? A : B) {
doSomething(node);
node = node.parent;
}
// A property might be a getter which has side effect...
// Or "doSomething" can modify "obj.foo".
while (obj.foo) {
doSomething(obj);
}
// A function call can return various values.
while (check(obj)) {
doSomething(obj);
}