← All examples

Nested match

A match alone in a case is a statement; a nested match that is the case's value says is match ….

nested_match.zg
# A `match` alone in a case is a statement (owner, 2026-09-29); a nested match that is the case's value
# says `is match …` (owner, 2026-10-07: a case says its value with `is`).
enum Order { cancelled, paid }
enum Ship { pickup, post }
MAIN {
    let 'o' := Order.paid;
    let 's' := Ship.post;
    match 'o' {
        cancelled { }
        paid { match 's' { pickup { std::print.useful["counter", newln]; } post { std::print.useful["mail", newln]; } } }
    }
    let 'price' := match 'o' { cancelled { is 0; } paid { is match 's' { pickup { is 5; } post { is 9; } }; } };
    std::print.useful['price', newln];
}
Output
mail
9