Break and continue in the shell

Source: Internet
Author: User

I see in the study not only has the break and the continue existence, as well as break-n and the continue-n existence so what difference does it have.

You can then write the test set code:

For i in a B c D
Do
Echo-n $i
For j in ' seq 10 '
Do
if test $j-eq 5
Then
Break//continue,break 2,cotinue 2
Fi
Echo-n $j

Done

  Echo

Done

The results are as follows:

Break

a1234

b1234

c1234

d1234

Break 2:

a1234

Continue

a1234678910

b1234678910

c1234678910

d1234678910

Continue 2:

a1234b1234c1234d1234

Get the following conclusions:

With no parameters:

The break loop can only exit the inner loop.

Continue can only remove the remaining code from this cycle

With parameters:

Break n can exit N-tier loops

Continue n will remove the N-layer cyclic residual code, and the number of single cycles is unchanged.

Break and continue in the shell

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.