continue
结束本次循环,继续执行下一个for,while或until循环。
概要
1continue [n]
主要用途
- 结束本次循环,继续执行下一个for,while或until循环;可指定从第几层循环继续执行。
参数
n(可选):大于等于1的整数,用于指定从第几层循环继续执行。
返回值
返回状态为成功除非n小于1。
例子
1# continue的可选参数n缺省值为1。
2for((i=3;i>0;i--)); do
3 # 跳到内层for循环继续执行。
4 for((j=3;j>0;j--)); do
5 if((j==2)); then
6 # 换成continue 1时结果一样
7 continue
8 fi
9 printf "%s %s\n" ${i} ${j}
10 done
11done
12# 输出结果
133 3
143 1
152 3
162 1
171 3
181 1
1# 当n为2时:
2# 跳到外层for循环继续执行。
3for((i=3;i>0;i--)); do
4 for((j=3;j>0;j--)); do
5 if((j==2)); then
6 continue 2
7 fi
8 printf "%s %s\n" ${i} ${j}
9 done
10done
11# 输出结果
123 3
132 3
141 3
注意
- 该命令是bash内建命令,相关的帮助信息请查看
help
命令。
来源:https://github.com/jaywcjlove/linux-command