ok
is false
if there are no more values to receive and the channel is closed.
Note: Only the sender should close a channel, never the receiver. Sending on a closed channel will cause a panic.
range-and-close.go
package main
import (
"fmt"
x, y := 0, 1
for i := 0; i < n; i++ {
c <- x
x, y = y, x+y
}
close(c)
func main() {
c := make(chan int, 10)
go fibonacci(cap(c), c)
for i := range c {
fmt.Println(i)
}