/// Returns n! using a loop.
int factorialLoop(int n) {
    int result = 1;
    for (int i = 2; i <= n; i++) {
        result *= i;
    }
    return result;
}

/// Returns n! using recursion.
int factorial(int n) {
    if (n <= 1) {
        return 1;
    }
    return n * factorial(n - 1);
}

void main() {
    IO.println(factorialLoop(5));
    IO.println(factorial(5));
}

// From Groundwork, chapter 12 (ch12-recursion-and-problem-solving), box 1.
// This example is from Groundwork, licensed CC BY-NC-SA 4.0.
// Run with: java ch12_01.java
