Last active
October 26, 2020 22:27
-
-
Save steph9009/27037a52ac2182f733417153f0c199fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
// fibonacci is a function that returns | |
// a function that returns an int. | |
func fibonacci() func() int { | |
a := 0 | |
b := 1 | |
c := 0 | |
return func() int { | |
c += a | |
a = b | |
b = c | |
return c | |
} | |
} | |
func main() { | |
f := fibonacci() | |
//for i := 0; i < 10; i++ { | |
for i := 0; i < 20; i++ { | |
fmt.Println(f()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment