Control flow
Browser runtime: loading…
Sapphire keeps branching and iteration compact with block syntax, trailing guards, ranges, and v0.8.0 match expressions. Each runnable snippet uses the same WASM engine as the playground.
if, while, and guards
Use if / elsif / else for branching and while for loops. A trailing if is useful for single-line guards:
print "passing" if score >= 60Ranges and match
Inclusive ranges use from..to. Sapphire v0.8.0 also adds match, with literal and range patterns plus _ as the wildcard arm.
control_flow.spr
Press Run to execute this snippet. ⌘↵ runs from the editor.