Linux Gvim shell break and Continue commands

Source: Internet
Author: User

#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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.