Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
循环第一次运行在shell脚本中继续_Shell_Loops_Continue - Fatal编程技术网

循环第一次运行在shell脚本中继续

循环第一次运行在shell脚本中继续,shell,loops,continue,Shell,Loops,Continue,如何在shell脚本中打破无限循环 我想在shell脚本中实现以下PHP代码: 这是你能做到的方法之一 嗯 这是你能做到的方法之一 HTHbreak也可以在shell脚本中工作,但是最好像Zsolt建议的那样,在while子句中检查条件,而不是在循环中检查条件。假设在检查条件之前循环中有一些更复杂的逻辑(即,您真正想要的是do..while循环),您可以执行以下操作: i=1 while true do if [ "$i" -eq 1 ] then continu

如何在shell脚本中打破无限
循环

我想在shell脚本中实现以下
PHP
代码:

这是你能做到的方法之一

这是你能做到的方法之一


HTH

break
也可以在shell脚本中工作,但是最好像Zsolt建议的那样,在
while
子句中检查条件,而不是在循环中检查条件。假设在检查条件之前循环中有一些更复杂的逻辑(即,您真正想要的是
do..while
循环),您可以执行以下操作:

i=1
while true
do
    if [ "$i" -eq 1 ]
    then
        continue
    fi
    # Other stuff which might even modify $i
    if [ $i -gt 9 ]
    then
        let i+=1
        break
    fi
done
如果您真的只想重复某件事
$count
次,有一种更简单的方法:

for index in $(seq 1 $count)
do
    # Stuff
done

break
也可以在shell脚本中工作,但是最好像Zsolt建议的那样,在
while
子句中检查条件,而不是在循环中检查条件。假设在检查条件之前循环中有一些更复杂的逻辑(即,您真正想要的是
do..while
循环),您可以执行以下操作:

i=1
while true
do
    if [ "$i" -eq 1 ]
    then
        continue
    fi
    # Other stuff which might even modify $i
    if [ $i -gt 9 ]
    then
        let i+=1
        break
    fi
done
如果您真的只想重复某件事
$count
次,有一种更简单的方法:

for index in $(seq 1 $count)
do
    # Stuff
done

由于您的代码检查$i==1,如果结果为真,则继续下一次迭代,因此在增加$i之前,实际上有一个无止境的循环。php代码中有一个无止境的循环。由于您的代码检查$i==1,如果结果为真,则继续下一次迭代,在增加$i之前,实际上,你有一个无止境的循环。你的php代码中有一个无止境的循环。