Control Flow

All control flow structures in Aria are expressions — they return values.

If Expressions

// As expression (returns a value)
grade := if score >= 90 { "A" }
         else if score >= 80 { "B" }
         else if score >= 70 { "C" }
         else { "F" }

// As statement
if debug {
    println("Debug mode enabled")
}

Match Expressions

Pattern matching with exhaustiveness checking — the compiler rejects incomplete matches:

fn area(s: Shape) -> f64 = match s {
    Circle{r} => 3.14159 * r * r
    Rect{w, h} => w * h
    Point => 0.0
}

// With guards
msg := match count {
    0 => "none"
    1 => "one"
    n if n < 10 => "a few"
    n => "{n} items"
}

// Matching on Option
match findUser(id) {
    Some(user) => greet(user)
    None => println("not found")
}

For Loops

// Range
for i in 0..10 {
    println(i)
}

// Inclusive range
for i in 0..=10 { ... }

// Iterable
for item in collection {
    process(item)
}

// With index
for (i, item) in collection.enumerate() {
    println("{i}: {item}")
}

// Key-value pairs
for (key, value) in myMap {
    println("{key} => {value}")
}

// For comprehension (returns a list)
squares := [x * x for x in 1..=10]
evens := [x for x in nums if x % 2 == 0]

While and Loop

// While
while condition {
    doWork()
}

// Infinite loop with break
loop {
    msg := ch.recv()
    if msg == "quit" { break }
    process(msg)
}

Block Expressions

Blocks return the value of their last expression:

total := {
    subtotal := items.sum()
    tax := subtotal * 0.08
    subtotal + tax
}

Next Steps