Skip to content

Commit db94c64

Browse files
committed
control-flow doc fixes
1 parent fc1c581 commit db94c64

6 files changed

Lines changed: 40 additions & 8 deletions

File tree

web/src/lib/tour/pages/break-continue.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Break & Countinue
1+
## Break & Countinue
22
Break and continue is used to control the flow of loops. `break;` will exit the loop, while `continue;` will skip to the next iteration of the loop.
33

44
[CODE]

web/src/lib/tour/pages/for-loops.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# For Loops
1+
## For Loops
22
For loops can iterate on ranges (`x..y` / `x..=y`) and arrays.
33

44
[CODE]

web/src/lib/tour/pages/if-else.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
## If / Else
22
If statements will run the code of a branch if the condition is true, and if all are false the else branch will run (if it exists).
33

4+
The following operators can be used in conditions:
5+
- `==` `!=` `>` `<` `>=` `<=`
6+
- `and`, `or`, `!`
7+
- `in`, `not in`
8+
49
[CODE]
10+
let x = 5;
11+
512
// the condition is true so the first branch will run
6-
if true {
13+
if x > 0 {
714
print("true");
815
}
916

1017
// the condition is false so the else branch will run
11-
if false {
18+
if x < 2 {
1219
print("false");
1320
} else {
1421
print("something else");
@@ -17,8 +24,33 @@ if false {
1724
// the condition is false but the else if condition is true so the else if branch will run
1825
if false {
1926
print("false");
20-
} else if true {
27+
} else if x == 5 {
2128
print("true");
2229
} else {
2330
print("false");
31+
}
32+
33+
// both sides have to be true for the branch to run
34+
if (x != 0) and (x < 10) {
35+
print("true");
36+
}
37+
38+
// either side can be true for the branch to run
39+
if (x == 5) or (x == 10) {
40+
print("true");
41+
}
42+
43+
// runs as 5 is a value of the array [4, 5, 6]
44+
if x in [4, 5, 6] {
45+
print("true");
46+
}
47+
48+
// runs as 5 is not a value of the array [1, 2, 3]
49+
if x not in [1, 2, 3] {
50+
print("true");
51+
}
52+
53+
// we use ! to negate a condition
54+
if !false {
55+
print("true");
2456
}

web/src/lib/tour/pages/infinite-loops.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Infinite Loops
1+
## Infinite Loops
22
Infinite loops keep running until you stop them.
33

44
[CODE]

web/src/lib/tour/pages/stdlib-json.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# JSON
1+
## JSON
22
Modu comes with a JSON library, but its only used for parsing json. Most
33

44
[CODE]

web/src/lib/tour/pages/while-loops.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# While Loops
1+
## While Loops
22
Keep doing something while a condition is true.
33
Condition is calculated before each iteration.
44

0 commit comments

Comments
 (0)