Special usage, continue and break usage of the while loop of the Linux learning path

Source: Internet
Author: User

In previous studies, we learned that the while loop shape is:

while expression;

Statement

...

Done

This grammatical structure loops as long as the expression meets the criteria to execute the statement in the loop body, or the loop is rolled out.


Two special while loops are described next

While loop attribute syntax one

While:;d o

Loop body

Done

This loop does not have expression, that is, there is no control condition, so the while using this notation, will be infinite loop down.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/3E/D8/wKioL1PH3JjQwrxLAAFi_0dTDtA685.jpg "title=" w1.png "alt=" Wkiol1ph3jjqwrxlaafi_0dtdta685.jpg "/>


In order to solve the Infinite loop (dead loop) and the control loop process, we can use the continue and break keywords to control.

Continue: Indicates that the statement following the continue in the current loop is not executed, goes directly to the next cycle, and does not exit the loop.

Break: Exits the loop directly.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/3E/D9/wKioL1PH4zaDuOdeAADwEOxXUmk255.jpg "title=" Con1.png "alt=" Wkiol1ph4zaduodeaadweoxxumk255.jpg "/>


While loop special syntax two

While Read Line;do

Statement

...

Done </path/to/somefile

This loop indicates that each row of a file is read sequentially and the contents of each row are assigned to the variable line.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/3E/D8/wKioL1PH3uvwC9mCAADMRy9b6AU356.jpg "title=" w2.png "alt=" Wkiol1ph3uvwc9mcaadmry9b6au356.jpg "/>


This article from the "Linux Learning Path" blog, declined reprint!

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.