Control Flow
if / else
Section titled “if / else”if health <= 0 { die()} else if health < 25 { playLowHealthWarning()} else { heal()}Type checking with is
Section titled “Type checking with is”Use expr is TypeName as a boolean condition:
if entity is Player { entity.takeDamage(10.0)}
let isEnemy = obj is Enemylet either = a is Player || a is NPCTernary
Section titled “Ternary”let status = health > 0 ? "alive" : "dead"Pattern matching with exhaustiveness checking. Two forms:
Value matching
Section titled “Value matching”when health { 0 => print("Dead") 1, 2, 3 => print("Critical") 0..25 => print("Low") 26..=100 => print("OK") else => print("Overheal")}Type matching
Section titled “Type matching”when result { is Success(value) => print(value) is Error(msg) => print("Error: " .. msg)}Guard clauses
Section titled “Guard clauses”when health { x if x < 0 => print("Invalid") x if x < 25 => print("Critical: $x") else => print("OK")}Multi-line arms
Section titled “Multi-line arms”when result { is Success(value) => { print(value) log(value) } is Error(msg) => print(msg)}Without a subject
Section titled “Without a subject”Replaces if/else chains:
when { health == 100 => print("Full") health <= 0 => print("Dead") else => print("Damaged")}while health > 0 { tick()}For over a collection
Section titled “For over a collection”for item in inventory { print(item.name)}For over a range
Section titled “For over a range”for i in 0..10 { print(i) // 0 to 9}
for i in 0..=10 { print(i) // 0 to 10}Loop control
Section titled “Loop control”break // exit loopcontinue // skip to next iteration