在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
Let's have some fun with functions. Implement a package main import "fmt" // fibonacci is a function that returns // a function that returns an int. func fibonacci() func() int { before := 0 now := 0 return func() int { if before == 0 { before++ return before } if now == 0 { now++ return now } temp := now now = before + now before = temp return now } } func main() { f := fibonacci() for i := 0; i < 10; i++ { fmt.Println(f()) } }
|
请发表评论