package main
import "fmt"
/*
Let's create a function which returns the channel, <-chan,
whenever called until the channel is closed. We can then
call the function in a for loop, and receive data, not all
at once, but in every iteration.
*/
func gen() <-chan int {
c := make(chan int)
go func() {
for i := 0; i < 5; i++ {
c <- i
}
close(c)
}()
return c
}
func main() {
g := gen()
for number := range g {
fmt.Println("The data is", number)
}
}