|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

 

 

posted on 2022-03-26 23:13  yanqi_vip  阅读(21)  评论(0)    收藏  举报

导航