Flow
Control flow in elz is only two ways(but maybe have macro extend the statement, it sounds good, I hope that will became true, too)
One is match.
let i = 1
match i {
1 => println("One"),
_ => println("What is this?"), // The end of match can add , or not. It's optional.
}
You should see "One"
print out.
Second is loop.(I am preparing design the condition of loop statement, hope it can suit more situations)
let mut i: num = 0
let n = 100
loop {
match i {
n => break, // can be found at this scope, so would not be binding value
k => { // binding the remained value
i += 1
println("{i}")
}
}
}
// print 0 .. 99
As you see, if match doesn't match a exist value or reference, it will binding value onto that ref name.
And as you see at ~~[previous section](/chapter1.md). Match can return a value(I mean it also is an expression).
let mut traffic_light = green
loop {
traffic_light = match traffic_light { // Start support at nim-elz v0.3.0
red => green,
green => yellow,
yellow => red
}
}
When => follow a expression.