Skip to main content

prefer-for-in

added in: 1.24.0
Pro+

Suggests using for-in loop instead of the regular loop.

Example

❌ Bad:

void fn(List<int> arr) {
// LINT: Prefer for-in loop over the regular for loop. To access the index, use the '.indexed' property on the collection.
for (var i = 0; i < arr.length; i += 1) {
...
}
}

✅ Good:

void fn(List<int> arr) {
for (final item in arr) {
...
}

for (final (index, item) in arr.indexed) {
...
}
}