Skip to content
Xen / docs

Search documentation

English · v0.1.0-demo.2

Type to search the documentation.

    한국어
    Xen / examples v0.1.0-demo.2

    Functions and loops

    Functions and loops

    Run from the repository or distribution root. Put xen on PATH, or substitute ./bin/xen.

    Terminal window
    xen check examples/control_flow.xen
    xen run examples/control_flow.xen
    20
    enough
    2
    1
    control_flow.xen
    // SPDX-License-Identifier: MIT OR Apache-2.0
    fn doubled(value: Int) -> Int {
    return value * 2;
    }
    fn main() {
    let mut total = 0;
    for number in 1..5 {
    total = total + doubled(number);
    }
    let label = if total >= 20 { "enough" } else { "more" };
    println(total);
    println(label);
    let mut remaining = 2;
    while remaining > 0 {
    println(remaining);
    remaining = remaining - 1;
    }
    }

    Download file

    Terminal window
    xen build examples/control_flow.xen -o app

    Run the generated executable on a compatible Linux machine.