Control flow
Conditions with if/elif/else, the only loop `each`, and `match` for values.
Conditions: if / elif / else
if x > 0
log "positive"
elif x == 0
log "zero"
else
log "negative"Keywords are spelled out in full (elif, else) — so they are understandable
at a glance.
if also works as an expression (ternary equivalent): it returns a value on
one line. The else branch is required. Wrap calls in the condition in parens.
pad = if h < 10 ("0" + str.str h) else (str.str h) # leading-zero
kind = if n % 2 == 0 "even" else "odd" # simple choice
r = if (str.len s) > 0 "full" else "empty" # call condition → parensIteration: each (the only loop)
Fluxon has only one loop — each. It iterates over a list, range, or map.
There is no while, for, or do-while:
each item in list # list elements
log item
each i in 1..5 # range: 1,2,3,4,5
log i
each k, v in map # map: key and value
log "$k = $v"Inside a loop:
skip— move to the next iteration (in other languagescontinue)stop— exit the loop (in other languagesbreak)
each n in nums
if n < 0
skip # skip negatives
if n > 100
stop # stop if over 100
log nWhere is while?
If you need to repeat based on a condition: iterate over a range
(each i in 1..n) or use recursion. One loop — one way.
Selecting by value: match
Comparing one value against several variants. Mostly for symbols:
match status
:new -> log "new"
:confirmed -> log "confirmed"
:cancelled -> log "cancelled"
_ -> log "unknown" # _ = defaultmatch and if do different things: if is for a boolean condition,
match is for distributing one value across variants. That is why both exist.
Important
match only works with a value (symbol or number). For a boolean condition
(like conf > 0.85) always use if/elif/else. Writing match true and
putting conditions under it is wrong — do not do this:
# WRONG:
match true
conf > 0.85 -> ...
# CORRECT:
if conf > 0.85
...