How to write a loop with a specified step in Rust

2 Answers

0 votes
fn main() {
  for i in (3..=10).step_by(2) {
    print!("{}, ", i);
  }
}
 
 
/*
run:
 
3, 5, 7, 9, 
 
*/

 



answered Apr 10 by avibootz
0 votes
fn main() {
    let mut i = 3;
    while i <= 10 {
        print!("{}, ", i);
        i += 2;
    }
}


/*
run:

3, 5, 7, 9, 

*/

 



answered Apr 10 by avibootz
...