I am new to Go and having some issues with figuring out a really simple problem. I am learning by working through some simple problem sets and at the moment am trying to print the sequence of Fibonacci numbers that are smaller than 10 million. My Fibonacci function is fine but I am not sure how to assign its value to a variable which I can then use in control structures. For instance:
package main
import "fmt"
func fib() func() int {
x, y := 0, 1
return func() int {
x, y = y, x+y
return x
}
}
func main() {
f := fib()
for f <= 10000000 {
fmt.Println(f())
}
}
I know I am missing something simple here but should this not keep calling my function and grabbing the next number in the Fibonacci sequence until that number is no greater than or equal to 10 million? I receive an error telling me there are mismatched types func() (int and int). I know this is dead simple and I am likely just an idiot. Thanks in advance.