楼主: eyewhite
2235 1

[编程问题求助] 关于 break 的问题 [推广有奖]

  • 0关注
  • 0粉丝

大专生

5%

还不是VIP/贵宾

-

威望
0
论坛币
81 个
通用积分
27.9443
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
392 点
帖子
24
精华
0
在线时间
34 小时
注册时间
2010-6-21
最后登录
2022-8-21

楼主
eyewhite 发表于 2016-5-11 11:35:19 |AI写论文
2论坛币
请问,嵌套foreach循环语句里面,用continue, break命令是跳出本层循环还是终止全部循环?如果是终止全部循环的话,怎么做才能只终止本层次的循环,而继续更高级的循环?

关键词:break bre continue foreach Reach continue

沙发
夏目贵志 发表于 2016-5-17 01:07:19
The continue command within a foreach, forvalues, or while loop breaks execution of the
    current loop iteration and skips the remaining commands within the loop.  Execution resumes
    at the top of the loop unless the break option is specified, in which case execution
    resumes with the command following the looping command.
帮助文件里已经说清楚了的help continue

自己验证一下也很容易
foreach a in 1 2 3 {
foreach b in 4 5 6 {
if `b'==5 {
continue, break
}
noi di "`a' `b'"
}
}
输出

1 4
2 4
3 4

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-6 06:55