📜  rust while 循环 - Rust 代码示例

📅  最后修改于: 2022-03-11 14:49:24.657000             🧑  作者: Mango

代码示例1
//from https://doc.rust-lang.org/rust-by-example/flow_control/while.html

fn main() {
    // A counter variable
    let mut n = 1;
    // Loop while `n` is less than 101
    while n < 101 {
        if n % 15 == 0 {
            println!("fizzbuzz");
        } else if n % 3 == 0 {
            println!("fizz");
        } else if n % 5 == 0 {
            println!("buzz");
        } else {
            println!("{}", n);
        }
        // Increment counter
        n += 1;
    }
}