rust/src/docs/needless_range_loop.txt
2022-09-09 13:36:26 +02:00

23 lines
No EOL
424 B
Text

### What it does
Checks for looping over the range of `0..len` of some
collection just to get the values by index.
### Why is this bad?
Just iterating the collection itself makes the intent
more clear and is probably faster.
### Example
```
let vec = vec!['a', 'b', 'c'];
for i in 0..vec.len() {
println!("{}", vec[i]);
}
```
Use instead:
```
let vec = vec!['a', 'b', 'c'];
for i in vec {
println!("{}", i);
}
```