Golang如何通过break退出for-select

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
func main() {
go demo()
for{
}
}
func demo(){
defer func() {
recover()
}()
LOOP:
for{
select {
case <- time.After(1*time.Second):
break LOOP
}
}
}

这里不能只使用break,必须要指定循环的开始语句LOOP