|NO.Z.00030|——————————|LinuxShell|——|Linux&Shell&流程控制.V11|——|continue|
一、流程控制——continue
### --- continue语法:
~~~ 再来看看 continue 语句,continue 也是结束流程控制的语句。
~~~ 如果在循环中,continue 语句只会结束单次当前循环,
~~~ 也画个示意图来说明下 continue 语句,如图 12-2 所示:

二、continue实验
### --- 实例一:
~~~ 还是用刚刚的脚本,不过退出语句换成 continue 语句,看看会发生什么情况
[root@localhost ~]# vi sh/continue.sh
#!/bin/bash
#演示 continue 语句
# Author: shenchao (E-mail: shenchao@atguigu.com)
for (( i=1;i<=10;i=i+1 ))
do
if [ "$i" -eq 4 ]
then
continue
#退出语句换成 continue
fi
echo $i
done
### --- 运行该脚本
### --- 赋予执行权限
~~~ # 注:continue 只会退出单次循环,所以并不影响后续的循环,所以只会少 4 的输出。
~~~ 这个例子和 break的例子做个比较,应该可以更清楚的说明 break 和 continue 的区别。
[root@localhost ~]# chmod 755 sh/continue.sh
[root@localhost ~]# sh/continue.sh
1
2
3
5 <——少了 4 这个输出
6
7
8
9
10
Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
——W.S.Landor
分类:
cdv008-shell
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通