不加入标签,只能break swtich
package main func main() { i := 10 for { i-- switch i { case 1: break } if i == -10 { break } println(i) } }
加入标签才能break 外面的循环
package main func main() { i := 10 OuterLoop: for { i-- switch i { case 1: break OuterLoop } if i == -10 { break } println(i) } }