Skip to main content

prefer-correct-for-loop-increment

added in: 1.8.0
Pro+
preset: recommended

Warns when a for loop increments a wrong variable.

Example

❌ Bad:

void main() {
var j = 1;

for (var i = 0; i < 10; j++) {} // LINT: Incremented variable differs from the declared one. Try checking it for a potential mistake.
}

✅ Good:

void main() {
var j = 1;

for (var i = 0; i < 10; i++) {}
for (var j = 0; j < 10; j++) {}
for (var i = 0; j < 10; j++) {}
}

Additional Resources