Generators

This example shows generators.

gen fib(n: uint) uint {
    var previous = 0
    var current = 1

    while (n > 0) {
        yield previous
        previous = current
        current = previous + current
        n--
    }
}

fn main() {
    for (n: fib(10)) {
        echo("${n}")
    }
}

# vi: set et sw=4 ts=4 tw=79: