@@ -4271,14 +4271,14 @@ for num in nums.iter() {
42714271}
42724272```
42734273
4274- There are two reasons for this. First, this is more semantic. We iterate
4275- through the entire vector, rather than iterating through indexes, and then
4276- indexing the vector. Second, this version is more efficient: the first version
4277- will have extra bounds checking because it used indexing, ` nums[i] ` . But since
4278- we yield a reference to each element of the vector in turn with the iterator,
4279- there's no bounds checking in the second example. This is very common with
4280- iterators: we can ignore unnecessary bounds checks, but still know that we're
4281- safe.
4274+ There are two reasons for this. First, this more directly expresses what we
4275+ mean. We iterate through the entire vector, rather than iterating through
4276+ indexes, and then indexing the vector. Second, this version is more efficient:
4277+ the first version will have extra bounds checking because it used indexing,
4278+ ` nums[i] ` . But since we yield a reference to each element of the vector in turn
4279+ with the iterator, there's no bounds checking in the second example. This is
4280+ very common with iterators: we can ignore unnecessary bounds checks, but still
4281+ know that we're safe.
42824282
42834283There's another detail here that's not 100% clear because of how ` println! `
42844284works. ` num ` is actually of type ` &int ` , that is, it's a reference to an ` int ` ,
0 commit comments