/// Returns the nth Fibonacci number, using a loop.
long fibLoop(int n) {
    long a = 0;
    long b = 1;
    for (int i = 0; i < n; i++) {
        long next = a + b;
        a = b;
        b = next;
    }
    return a;
}

void main() {
    IO.println(fibLoop(50));
}

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