首页 > 代码库 > Shell 编程基础之 Break, Continue 练习

Shell 编程基础之 Break, Continue 练习

一、语法

break:用来跳出循环。break N 可以跳出多层循环

break
break N

continue:用来跳过循环。continue N 可以跳过多层循环

continue
continue N

二、详细与区别

  1. break
    for var1 in 1 2 3do  for var2 in 0 5  do    if [ "$var1" -eq "2" -a "$var2" -eq "0" ]; then      break 2    else      echo "$var1 $var2"    fi  donedone
    user@ae01:~$ ./test.sh1 01 5
  2. continue
    for var1 in 1 2 3do  for var2 in 0 5  do    if [ "$var1" -eq "2" -a "$var2" -eq "0" ]; then      continue 2    else      echo "$var1 $var2"    fi  donedone
    user@ae01:~$ ./test.sh1 01 53 03 5

Shell 编程基础之 Break, Continue 练习