package main
import (
"fmt"
)
func main() {
c := make(chan int, 0)
go func() {
i := 10
for i > 0 {
c <- i
i--
}
close(c)
}()
for {
fmt.Println("loop")
select {
case _, ok := <-c:
fmt.Println("recv:", ok)
if !ok {
fmt.Println("break for")
break
}
}
}
}
不能break for语句,貌似break了select语句,程序一直在死循环,不能正常退出!!
==================================================================
recv: false
break for
loop
recv: false
break for
loop
recv: false
break for
loop
recv: false
break for
loop
recv: false
break for
有疑问加站长微信联系(非本文作者)