break
break
swtich到底跳到哪
只能跳出自己的swtich
package main
import (
"fmt"
"time"
)
func main() {
t := 0
for {
switch t {
case 3:
break
default:
t++
fmt.Println(t)
}
fmt.Println("over1")
time.Sleep(time.Second*2)
}
fmt.Println("over2")
}
## 输出
over1
2
over1
3
over1
over1
over1
over1
一直输出over1
跳到指定位置
package main
import (
"fmt"
"time"
)
func main() {
t := 0
LOOP:
for {
for {
switch t {
case 3:
break LOOP
default:
t++
fmt.Println(t)
}
fmt.Println("over1")
time.Sleep(time.Second * 2)
}
}
fmt.Println("over2")
}
## 输出
1
over1
2
over1
3
over1
over2