rust for循环步长-1,反向逆序遍历

fn main() {
    for i in (0..3).rev().step_by(1) {
        print!("{}", i);
    }
}
// 打印结果:210

Trait std::iter::Iterator

  • fn rev(self) -> Rev where Self: Sized + DoubleEndedIterator
  • fn step_by(self, step: usize) -> StepBy where Self: Sized

你可能感兴趣的:(rust,rust,开发语言)