Docs / Tutorial
03 · Control flow
No parens on if/for. Loop and match ranges use :, including the start and excluding the end: [start, end). Statement-start -> is continue, <- is break.
Source
@main
fn main() int {
age := 16
if age >= 18 {
println("adult")
} else {
println("minor")
}
match age {
0:13 {
println("child")
}
13:20 {
println("teen")
}
else {
println("adult")
}
}
mut n := 3
while n > 0 {
println(n)
n -= 1
}
mut sum := 0
for i in 0:5 {
if i == 2 {
->
}
if i == 4 {
<-
}
sum += i
}
println(sum)
<< 0
}Build (from the language repo root; swap the binary for your platform):
xu run examples/03_control_flow/main.xu
# or: xu build examples/03_control_flow/main.xu
# default artifact is ./main on mac/linux, ./main.exe on Windows
Run from the separate examples repository root; source files live under examples/.