continue 主要用途在于结束本次循环,继续执行下一个 for,while 或 until 循环;可指定从第几层循环继续执行。
语法格式:continue
常用参数:
n | 大于等于 1 的整数,用于指定从第几层循环继续执行 |
参考实例
continue 的可选参数 n 缺省值为 1:
for((i=3;i>0;i--)); do
for((j=3;j>0;j--)); do
if((j==2)); then
continue
fi
printf "%s %s\n" ${i} ${j}
done
done
# 输出结果 3 3 3 1 2 3 2 1 1 3 1 1
当 n 为 2 时: 跳到外层 for 循环继续执行:
for((i=3;i>0;i--)); do
for((j=3;j>0;j--)); do
if((j==2)); then
continue 2
fi
printf "%s %s\n" ${i} ${j}
done
done
# 输出结果 3 3 2 3 1 3
正文完
发表至: 其他命令
2020-01-21