Go by Example - Range over Channels
Go by Example
Go is an open source programming language designed for building simple, fast, and reliable software.
Go by Example is a hands-on introduction to Go using annotated example programs. Check out the first example or browse the full list below.
Go by Example: Range over Channels
在前面的示例中看到for
和range
语句如何给基本数据类型提供迭代操作,我们也可以用它们来迭代channel中接收到的值。
1 | package main |
1 | tashuo:golang ta_shuo$ go run r_channel.go |
上面的示例中也看出可以关闭掉一个还有待接收值的非空管道。