|
|
|
|
|
by WhyNotHugo
14 days ago
|
|
'for' loops in Rust do the same: they create an iterator and then iterate over that. You can write the exact same loop with `let mut iter = v.iter(); while Some(x) = iter.next()`. 'for' loops in Rust are purely syntax sugar, and I somewhat wish they didn't exist. They provide you two ways of doing the same thing, but one of them hides the details from you. Having 'for' as a keyword is nice for folks coming from other languages, but then it hides the possibility of other interesting usages, like cloning an iterator inside a loop. |
|