package main
import "fmt"
func fib(n int, ch chan<- int) {
x, y := 0, 1
for i := 0; i < n; i++ {
ch <- x
x, y = y, x+y
}
}
func main() {
// create an unbuffered channel
ch := make(chan int)
// generate the first 10 Fibonacci numbers
// in a separate goroutine
go fib(10, ch)
// read values from the channel until it's closed
for i := 0; i < 10; i++ {
fmt.Println(<-ch)
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: