nandi/rustnimpublic Fork 0
main
Commits
Clone
git clone https://git.rickub.com/nandi/rustnim.git
git clone ssh://git@rickub.com/nandi/rustnim.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

006-control-flow.rs · 28 lines · 451 BRust Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
fn classify(n: i32) -> i32 {
    if n < 0 {
        -1
    } else if n == 0 {
        0
    } else {
        1
    }
}

fn main() {
    let mut total: i32 = 0;
    for i in -3..4 {
        total += classify(i);
        println!("{} -> {}", i, classify(i));
    }
    let mut k: i32 = 0;
    while k < 3 {
        k += 1;
    }
    loop {
        k += 1;
        if k > 5 {
            break;
        }
    }
    println!("total={} k={}", total, k);
}