Shell script Loop statement--continue and break

Source: Internet
Author: User

Continue and break are commonly used in the while, until, select Loop statements, exit this round or all loops under specified conditions, we need to use the example to verify the results of the operation, it is good to understand. But it's really not a good idea to read the text.

Continue usage

Continue used in the loop body
Continue [n]: End of the nth layer of the current cycle, and directly into the next round of judgment; the inner layer is the 1th floor.
While CONDTIITON1; Do
CMD1
...
if CONDITION2; Then
Continue
Fi
Cmdn
...
Done

Example Demo:
#!/bin/bash

#Author: Wangjun
#Contact qq:183530300
#Version: 1.0
#Create time:2016-08-20 12:23:58
#Description: Break and Continue Test

Declare-i i=0

while [[$I-lt 5]];d o
Let i++
if [[$I-eq 3]];then
Continue
#break
Fi
Echo $I
Done

650) this.width=650; "title=" Break.png "src=" http://s2.51cto.com/wyfs02/M00/86/37/ Wkiom1e4bjsqbyyraaar-7abrew205.png "alt=" Wkiom1e4bjsqbyyraaar-7abrew205.png "/>

Break usage

Break is used in the loop body
Break [n]: Early end of the nth layer cycle, the inner layer is the 1th layer
While CONDTIITON1; Do
CMD1
...
if CONDITION2; Then
Break
Fi
Cmdn
...
Done

Example Demo:
#!/bin/bash

#Author: Wangjun
#Contact qq:183530300
#Version: 1.0
#Create time:2016-08-20 12:23:58
#Description: Break and Continue Test

Declare-i i=0

while [[$I-lt 5]];d o
Let i++
if [[$I-eq 3]];then
#continue
Break
Fi
Echo $I
Done

650) this.width=650; "title=" Continue.png "src=" http://s5.51cto.com/wyfs02/M02/86/37/ Wkiol1e4bdpro2vgaaapzbstybu916.png "alt=" Wkiol1e4bdpro2vgaaapzbstybu916.png "/>

This article is from the "Love Firewall" blog, be sure to keep this source http://183530300.blog.51cto.com/894387/1840695

Shell script Loop statement--continue and break

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.