Control Flow — Mapanare
Conditionals, loops, pattern matching, and ranges.
If / Else
No parentheses around the condition, braces are required.
if x > 0 {
print("positive")
} else if x == 0 {
print("zero")
} else {
print("negative")
}
For Loops
for i in 0..5 { print(i) } // exclusive range: 0,1,2,3,4
for i in 1..=5 { print(i) } // inclusive range: 1,2,3,4,5
for name in names { print(name) } // iterate over list
Ranges
a..b — exclusive (a to b-1). a..=b — inclusive (a to b).
Match Expressions
Pattern matching with exhaustiveness checking:
enum Color { Red, Green, Blue, Custom(Int, Int, Int) }
fn describe(c: Color) -> String {
match c {
Red => "red",
Green => "green",
Blue => "blue",
Custom(r,g,b) => "custom color",
}
}
Use _ as a wildcard to match any value without binding it.