- I need to iterate over a vector. Normally I would just do
for x in v.iter() {
...
}
- However, I want to start with the 2nd element (index 1), without constructing a subvector. How can I skip the first element?
for x in v.iter() {
...
}
for x in v.iter().skip(1) { ... }
or
for x in &v[1..] { ... }
(Note: If v
is empty, then the first version will do nothing, while the second version will panic.)
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.