nandi/rustnimpublic Fork 0
99b837678a29fedd20bb68a5117a6621d8d178b4
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
Add the differential test runner, and a lowering to measure with it 8ac32af nandithebull 10h ago1fn classify(n: i32) -> i32 {
2 if n < 0 {
3 -1
4 } else if n == 0 {
5 0
6 } else {
7 1
8 }
9}
10
11fn main() {
12 let mut total: i32 = 0;
13 for i in -3..4 {
14 total += classify(i);
15 println!("{} -> {}", i, classify(i));
16 }
17 let mut k: i32 = 0;
18 while k < 3 {
19 k += 1;
20 }
21 loop {
22 k += 1;
23 if k > 5 {
24 break;
25 }
26 }
27 println!("total={} k={}", total, k);
28}