|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的例子做个比较,应该可以更清楚的说明 breakcontinue 的区别。

[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

 

 

posted on   yanqi_vip  阅读(10)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示