continue命令 – 结束本次循环

来源: 柚子科技、WordPress 主题、WordPress插件    日期: 2021-12-15    标签:    作者: WordPress主题themes插件plugins开发定制    阅读数: 5

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 %sn" ${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 %sn" ${i} ${j}    done done  # 输出结果 3 3 2 3 1 3  

链接到文章: https://uziwp.com/5217.html

评论已关闭