There is this website called rosetta code that has algorithms in all languages so you can learn and compare when learning new languages.
Here I saw that one of the solutions for go lang is pretty interesting but I don't fully understand it.
func fib(c chan int) {
a, b := 0, 1
for {
c <- a
a, b = b, a+b
}
}
func main() {
c := make(chan int)
go fib(c)
for i := 0; i < 10; i++ {
fmt.Println(<-c)
}
}
Here are some of my doubts
How does the infinite for loop know when to stop? How does the c channel communicate this? What is the logical sequence between the func calls?
Thanks for the help kind strangers.