If you make the changes proposed by Kevin Ballard , then
package main import "fmt"
Output:
1 2 3 5 8 13 21 34 55 89
The output is not a Fibonacci sequence .
For the Fibonacci sequence ,
package main import "fmt" func fibonacci() func() int { a, b := 0, 1 return func() (f int) { f, a, b = a, b, a+b return } } func main() { f := fibonacci() for i := 0; i < 10; i++ { fmt.Println(f()) } }
Output:
0 1 1 2 3 5 8 13 21 34
peterSO
source share