Factorial in Ceylon

Example for versions Ceylon M1

This example calculates factorials iteratively. variable keyword points out that the value of the variable fact is going to be changed later (exactly the opposite of Java keyword final). Integer data type allows to store values of factorial without overflow. The arguments of print are concatenated without any explicit operator, but for this the first and the last elements of the list to be concatenated have to be string literals.

void run() {
    variable Integer fact := 1;
    for (i in 0..16) {
        print("" i "! = " fact "");
        fact *= i + 1;
    }
}