当前位置:网站首页>Golang Break、Continue跳出多层循环
Golang Break、Continue跳出多层循环
2022-08-07 04:06:00 【@航空母舰】
Break
break 语句可以结束 for、switch 和 select 的代码块。Break在没有使用标签的时候break只是跳出了一层for循环。break 语句还可以在语句后面添加标签,表示退出某个标签对应的代码块,标签要求必须定义在对应的 for、switch 和 select 的代码块上。
func main() {
OuterLoop:
for i := 0; i < 2; i++ {
for j := 0; j < 5; j++ {
switch j {
case 2:
fmt.Println(i, j)
break OuterLoop
case 3:
fmt.Println(i, j)
break OuterLoop
}
}
}
}continue
continue 语句可以结束当前循环,开始下一次的循环迭代过程,仅限在 for 循环内使用。在 continue 语句后添加标签时,表示开始标签对应的循环。例如:
func main() {
OuterLoop:
for i := 0; i < 2; i++ {
for j := 0; j < 5; j++ {
switch j {
case 2:
fmt.Println(i, j)
continue OuterLoop
}
}
}
}边栏推荐
猜你喜欢

BI skills丨Filter reset

项目管理知识点

Wechat applet's homestay room reservation uniapp applet

Scrollbar for TreeView in wpf

Wireless Video Surveillance of Construction Site Industrial Grade Wireless Router Application

危险,请马上替换代码中的BeanUtils

"go1.15.3" does not match go tool version "go1.13.8"

创建桌面安装程序需要什么工具?

机器学习初学者易踩的5个坑

Wonderful Review|Cloud Native Meetup Guangzhou Station
随机推荐
tiup cluster display
Reading Notes - RetinaFace: Single-stage Dense Face Localisation in the Wild
【LeetCode每日一题】——153.寻找旋转排序数组中的最小值
Project management knowledge points
2022 Niu Ke Duo School Six M-Z-Game on grid (dynamic programming)
堆(溯流从源——树)
小程序的父------------>子的通信
MySQL中自带的表
5G/4G water resource remote control terminal
【Metaverse系列一】元宇宙的奥秘
【诡秘之主】源质篇
等比例缩放
The fourth virtual camera: who is calling the v4l2_camera_HAL camera driver
What tools do I need to create a desktop installer?
LED驱动程序优化-分层
【诡秘之主】封印物篇
tiup cluster display
解析wpf控件内部的结构
MySQL - 存储过程和函数
The sword refers to Offer II 029. Sorted circular linked list - pure linked list implementation