I know that switch
/select
statements break automatically after every case. I am wondering, in the following code:
for {
switch
Yes, break
breaks the inner switch
.
https://play.golang.org/p/SZdDuVjic4
package main
import "fmt"
func main() {
myloop:
for x := 0; x < 7; x++ {
fmt.Printf("%d", x)
switch {
case x == 1:
fmt.Println("start")
case x == 5:
fmt.Println("stop")
break myloop
case x > 2:
fmt.Println("crunching..")
break
default:
fmt.Println("idling..")
}
}
}
0idling.. 1start 2idling.. 3crunching.. 4crunching.. 5stop Program exited.