Shell Getting Started Tutorial: Process Control (7) Break and continue

Source: Internet
Author: User

Section one: Breank commands

4 loops for, while, until, select, if you want to end the loop early, you can use the break command in the loop. When you perform a break, you jump out of a layer of loops, and if you want to jump out of a multilayer loop, you can add the number of layers n after the break command (n must be greater than or equal to 1).

#!/bin/bashfor ((i=1;i<=10;i++)) doif [$i-eq 6]; Thenbreakfiecho $idone

Line 5, if the value of I equals 6, jump out of the loop, that is, end the loop .

Section II: Continue commands

The Continue is used in the 4 loop statements for, while, Untile, select. Unlike break, continue will jump out of this loop and start again with the next loop.

Example:

#!/bin/bashfor (i=1;i<=10;i++;)) doif [$i-eq 6]; Thencontinuefiecho $idone

Shell Getting Started Tutorial: Process Control (7) Break and continue

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.