Home /Modules/impl/factorial.sleela

factorial.sleela

impl/examples/factorial.sleela · 19 line(s) · sleela

// Recursion + method calls, all lowered to CALL/RET on the C core.
class Factorial {

    int fact(int n) {
        if (n <= 1) {
            return 1;
        }
        return n * fact(n - 1);
    }

    void main() {
        int i = 1;
        while (i <= 10) {
            print("fact(" + i + ") = " + fact(i));
            i = i + 1;
        }
    }
}