一、语法
break:用来跳出循环。break N 可以跳出多层循环
break
break N
continue:用来跳过循环。continue N 可以跳过多层循环
continue
continue N
二、详细与区别
- break
for var1 in 1 2 3 do for var2 in 0 5 do if [ "$var1" -eq "2" -a "$var2" -eq "0" ]; then break 2 else echo "$var1 $var2" fi done done
user@ae01:~$ ./test.sh 1 0 1 5
- continue
for var1 in 1 2 3 do for var2 in 0 5 do if [ "$var1" -eq "2" -a "$var2" -eq "0" ]; then continue 2 else echo "$var1 $var2" fi done done
user@ae01:~$ ./test.sh 1 0 1 5 3 0 3 5