#break和continue命令: During a loop, sometimes you need to force the loop to break out when the loop end condition is not reached
#break: Allow all loops to jump out (end all loops after execution)
1 while: #死循环写法 #2 Do3 Echo-N"Input A number between 1 to 5:"4 Read Anum5 Case${anum}inch6 1|2|3|4|5) 7 Echo "Your number is ${anum}"8 ;;9*) Ten Echo "You don't Select a number Betwwen 1 to 5 and game over!" One Break A ;; - Esac - Done
#循环嵌套, break can be followed by a parameter that indicates jumping out of the first layer of the loop
#例: If var1=2 and var2=0, jump out of the loop
forVar1inch 1 2 3 Do forVar2inch 0 5 Do if[${var1}-eq2-A ${var2}-eq0 ] Then Break2 Else Echo "${var1} ${var2}" fi Done Done
#continue命令: Do not jump out of all loops, just jump out of the current loop
#运行代码发现, the number entered is not 1-5, and the loop will not be terminated. echo "Game Over" is never executed
1 while :2 Do3 Echo "Input A number between 1 to 5"4 Read Anum5 Case${anum}inch6 1|2|3|4|5)7 Echo "Your number is ${anum}"8 ;;9*)Ten Echo "You don't select a number between 1 to 5!" One Continue A Echo "Game over" - ;; - Esac the Done
#寻找偶数
1numbers="1 2 3 4 5 6"2 forNuminch${numbers}3 Do4Q= 'Expr${num}%2 `5 if[${q}-eq0 ]6 Then7 Echo "Number is an even number"8 Continue9 fiTen Echo "Found Odd number" One Done
Linux Gvim shell break and Continue commands