-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03_control.mno
More file actions
47 lines (43 loc) · 768 Bytes
/
Copy path03_control.mno
File metadata and controls
47 lines (43 loc) · 768 Bytes
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Lesson 03 — Control flow: if, while, for, break, continue
fn classify(n: int) -> str {
if n < 0 {
return "neg"
} else {
if n == 0 {
return "zero"
}
return "pos"
}
}
fn sum_to(n: int) -> int
requires n >= 0
{
let i = 0
let s = 0
while i < n {
s = s + i
i = i + 1
}
return s
}
fn main() {
print(classify(-1))
print(classify(0))
print(classify(7))
print(sum_to(10))
for i in 0..5 {
if i == 2 {
continue
}
if i == 4 {
break
}
print(i)
}
}
test "control" {
assert classify(-3) == "neg"
assert classify(0) == "zero"
assert classify(9) == "pos"
assert sum_to(10) == 45
}