How to iterate over a range with a custom step in Rust?
In Rust we can iterate through a range using functionIterator::step_by
Example of iterating over a range with a custom step
In below example we will use the function step_by().fn main() {
for x in (1..10).step_by(2) {
println!("{}", x);
}
}
Output
1
3
5
7
9
3
5
7
9