Skip to main content

avoid-unmodified-loop-condition

effort: 5m
pro+

Warns when a loop condition is not modified within the loop.

Example

❌ Bad:

void fn(String left, String right) {
// LINT: None of the local variables in this condition are modified within the loop.
// Try checking for a potential mistake.
while (left.isNotEmpty) {
print(left);
}
left = '';

// LINT: None of the local variables in this condition are modified within the loop.
// Try checking for a potential mistake.
while (left != right) {
print(left);
}
}

✅ Good:

void fn(String left, String right) {
while (left.isNotEmpty) {
print(left);
left = '';
}

// LINT: None of the local variables in this condition are modified within the loop.
// Try checking for a potential mistake.
while (left != right) {
print(left);
}
}