Control Flow

AodhML provides familiar control flow constructs with a focus on clarity and exhaustiveness checking.

If / Else If / Else

fn grade(score: f64) -> String {
    if score >= 90.0 {
        return "A"
    } else if score >= 80.0 {
        return "B"
    } else if score >= 70.0 {
        return "C"
    } else {
        return "F"
    }
}

For Loops

Iterate over ranges or collections:

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

// Inclusive range
for i in 0..=10 {
    println(i)  // 0 to 10
}

// Collection iteration
for item in items {
    println(item)
}

// With index
for i, item in items {
    println(i, item)
}

While Loops

mut count = 0
while count < 10 {
    println(count)
    count = count + 1
}

Match Expressions

Pattern matching with exhaustiveness checking:

fn describe(value: Option<i32>) -> String {
    match value {
        Some(x) if x > 0 => "Positive: " + x,
        Some(0) => "Zero",
        Some(x) => "Negative: " + x,
        None => "No value",
    }
}

Break & Continue

for i in 0..100 {
    if i % 2 == 0 { continue }
    if i > 20 { break }
    println(i)
}