How should I go if I want to iterate with a custom step in stable Rust? Essentially something like the C/C++
for (in
Since this question was asked, the itertools crate, has become fairly standard as a dependency. You can do what you want very simply with the step() method:
extern crate itertools; // 0.7.8
use itertools::Itertools;
fn main() {
for i in (0..=10).step(2) {
println!("i = {}", i);
}
}
In your Cargo.toml
:
[dependencies]
itertools = "0.7.8"