fizzbuzz/fibonacci.tour.go

22 lines
304 B
Go
Raw Normal View History

2012-08-07 00:37:28 +00:00
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
a := 0
b := 1
return func () int {
a, b = b, a + b;
return a;
}
}
func main() {
f := fibonacci()
for i := 0; i < 10; i++ {
fmt.Println(f())
}
}