Skip to main content

Flow Control

Statements that decide which steps run. The everyday forms (when, branch, match, foreach, stop) are covered with examples in Language Guide → Control flow; this page is the quick reference plus condition/if and sequence.

when / else

when user.balance >= 100 {
send.text("Affordable!")
} else {
send.text("Too expensive.")
}

Optional if guard:

when user.role == "admin" if user.verified { send.text("Verified admin.") }

condition / if

A plain boolean branch. when is the idiomatic form; condition is its underlying node and if is an alias.

if user.subscribed {
send.text("Thanks for subscribing!")
}

branch

Route a value into named string arms with optional default, timeout, and error:

branch flow.choice {
"a" { send.text("You picked A") }
"b" { send.text("You picked B") }
default { send.text("Unknown choice") }
}

Most often used to handle an ask.* result — see Input.

match

Literal values, numeric ranges (low..high), a wildcard _, and optional per-arm if guards:

match user.score {
0 { send.text("Zero") }
1..50 { send.text("Low") }
51..100 if user.premium { send.text("Pro tier") }
_ { send.text("Off the charts") }
}

foreach

Iterate an array, optionally capturing a 0-based index:

foreach item in user.cart {
send.text(`• ${item.name}`)
}

foreach item, i in flow.ranked {
set { flow.pos = i + 1 }
send.text(`${flow.pos}. ${item.name}`)
}
note

There is no user while loop. Iterate with foreach. For a counted loop, foreach n in array.range(0, 10) { … }.

stop

End the current flow immediately:

when user.banned { send.text("🚫 Banned.") stop }

sequence

Run several named sub-branches one after another, in order. Useful for orchestrating a fixed series of steps:

sequence {
step validate { /* … */ }
step charge { /* … */ }
step confirm { /* … */ }
}

See also