Shell control structure (break and continue statements)

Source: Internet
Author: User

Shell control structure (break and continue statements) the break statement can end the execution of while, for, until, select, and other structures, that is, jumping out of the structure. After exiting the loop, go to the done statement and continue execution. [Root @ sziit ~] # Vim breaks. sh (example )#! /Bin/bash # filename: breaksecho "enter the number: "read Nfor I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 doif [$ I-eq $ N]; thenecho "------- exit for loop -----" breakelseecho "------ current is $ I loop ----" fidone [root @ sziit ~] #. /Breaks. sh (test result) enter the number: 5 ------ current is 1 loop ---------- current is 2 loop ---------- current is 3 loop ---------- current is 4 loop ----------- exit for loop ----- The continue statement is used to skip the code in this loop, directly jump back to the starting position of the loop. If the condition is true, the next loop is started; otherwise, the loop is exited. [Root @ sziit ~] # Vim continues. sh (example )#! /Bin/bash # filename: continuesecho "output the number:" read Necho "----------------" int = 1for int in 'seq 7' doif [$ N-gt 7]; thenecho "please enter a number [1-7]" breakelif [$ N-le 0]; thenecho "please enter a number [1-7]" breakelseif [$ int-eq $ N]; thenecho "-" continuefifiecho "$ int" done [root @ sziit ~] #./Continues. sh (test result) output the number: 4------------------123-567

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: 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.