typestar

Iterative Fibonacci in Go

Fibonacci without recursion, two variables and a loop.

func fib(n int) int {
    a, b := 0, 1
    for i := 0; i < n; i++ {
        a, b = b, a+b
    }
    return a
}

Keywords and builtins used here

The run, in numbers

Lines
7
Characters to type
86
Tokens
40
Three-star pace
90 tpm

At the three-star pace of 90 tokens a minute, this run takes about 27 seconds.

Type this snippet

Step 6 of 6 in Functions, step 15 of 30 in Language basics.

← Previous Next →

Iterative Fibonacci in other languages