]> git.lizzy.rs Git - rust.git/blob - src/docs/needless_range_loop.txt
Auto merge of #9421 - xphoniex:fix-#9420, r=giraffate
[rust.git] / src / docs / needless_range_loop.txt
1 ### What it does
2 Checks for looping over the range of `0..len` of some
3 collection just to get the values by index.
4
5 ### Why is this bad?
6 Just iterating the collection itself makes the intent
7 more clear and is probably faster.
8
9 ### Example
10 ```
11 let vec = vec!['a', 'b', 'c'];
12 for i in 0..vec.len() {
13     println!("{}", vec[i]);
14 }
15 ```
16
17 Use instead:
18 ```
19 let vec = vec!['a', 'b', 'c'];
20 for i in vec {
21     println!("{}", i);
22 }
23 ```