if, assert, and loops to express conditional logic.
The match expression is a powerful “pattern-matching” feature.
if statement
Similar to common languages, optionally followed by else if or else.
if and else must be enclosed in { ... }:
assert statement
assert throws an exception if a condition is false.
match expression
match is used to perform different actions for different values of a variable.
One common use case is routing values of a union type:
match is equivalent to a series of if-else checks:
match can also be used for expressions (switch-like behavior):
Ternary operator
A ternarycondition ? when_true : when_false is also available:
when_true and when_false are different, a resulting type is a union.
However, this is typically not the intended result, so the compiler reports an error.
while loops
while and do-while loops repeatedly execute their bodies while the condition remains true.
while checks the condition first and may not execute the body at all, whereas do-while runs the body first.
while is used to iterate over maps:
repeat loop
The repeat (N) statement executes a block N times:
N does not have to be a constant; it may also be a variable.
Break and continue in loops
The keywordsbreak and continue are not implemented yet, and a for loop may be added in future versions.