All examples
Language

Functions and control flow

Use recursion, conditions, loops, and local scope.

Download .aner source
control_flow.aner
fn main() -> Unit {
    var total: Int64 = 0;
    var i = 1;
    while i <= 5 {
        total = total + i;
        i = i + 1;
    }

    if total == 15 {
        print("sum verified");
    } else {
        print("unexpected sum");
    }
    print(total);
    print(factorial(5));

    let label = "outer";
    {
        let label = "inner";
        print(label);
    }
    print(label);
}

// Forward function references and recursion are supported.
fn factorial(n: Int64) -> Int64 {
    if n <= 1 {
        return 1;
    } else {
        return n * factorial(n - 1);
    }
}
// Expected output:
// sum verified
// 15
// 120
// inner
// outer

Make it your experiment.

With Aner installed, save this program as examples/control_flow.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.

Terminal
aner check examples/control_flow.aner
aner run examples/control_flow.aner

The aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.

Iris and Wine are teaching datasets with their own attribution. Example outcomes are not comparative benchmarks or evidence of clinical validity.

Dataset sources & attribution
Install Aner