1、continue指令并不会直接终止整个循环,而只是终止当前变量中的一个指令。
#!/bin/bash
for (( i=10; i<20; i++))
do
if (( i>0 && i<15));then
continue
else
echo "Number is $i"
fi
done
# 执行结果
% sh 19.continue_circulation.sh
Number is 15
Number is 16
Number is 17
Number is 18
Number is 19
2、continue指令指定跳出循环层级
continue [数字]:用来指定跳出层级;多个循环嵌套式,默认只跳出内循环。
for (( i=1; i<=3; i++))
do
for (( j=1; j<=3; j++))
do
if (( j==3));then
continue 2
else
echo "坐标为:($i,$j)"
fi
done
done
# 执行结果,直接把内循环终止
% sh 19.continue_circulation.sh
坐标为:(1,1)
坐标为:(1,2)
坐标为:(2,1)
坐标为:(2,2)
坐标为:(3,1)
坐标为:(3,2)
最后
以上就是无辜悟空最近收集整理的关于Shell中控制循环的continue指令的全部内容,更多相关Shell中控制循环内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复