- Use
if,assert, and loops for conditional logic. - Use
matchexpression for pattern matching.
if statement
if statement works as in most languages. else if and else blocks are optional.
true:
if and else must be enclosed in { ... }:
assert statement
assert throws an exceptions if a condition is false.
match expression
match is used to perform different actions for different values of a variable. A 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
The ternary formcondition ? when_true : when_false is available:
when_true and when_false differ, the result becomes a union type. In most cases this is unintended, 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 its block N times:
N may be either a constant or a variable.
break and continue
The keywords break and continue are not supported.