mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 01:21:38 +08:00
fix: coding style and file format for chapter 6.
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
package main
|
||||
|
||||
// fib returns a function that returns
|
||||
// successive Fibonacci numbers.
|
||||
func fib() func() int {
|
||||
a, b := 1, 1
|
||||
return func() int {
|
||||
a, b = b, a+b
|
||||
return b
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
f := fib()
|
||||
// Function calls are evaluated left-to-right.
|
||||
// println(f(), f(), f(), f(), f())
|
||||
for i:=0; i<=9; i++ {
|
||||
println(i+2, f() )
|
||||
}
|
||||
}
|
||||
package main
|
||||
|
||||
// fib returns a function that returns
|
||||
// successive Fibonacci numbers.
|
||||
func fib() func() int {
|
||||
a, b := 1, 1
|
||||
return func() int {
|
||||
a, b = b, a+b
|
||||
return b
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
f := fib()
|
||||
// Function calls are evaluated left-to-right.
|
||||
// println(f(), f(), f(), f(), f())
|
||||
for i := 0; i <= 9; i++ {
|
||||
println(i+2, f())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user