Shell-jump out of the loop break and continue

Source: Internet
Author: User

Break:

Berak statements are usually used in loop statements and switch statements, and when the break statement is used in a do-while, for, and while Loop statement, the program terminates the statement following the loop. Usually the break statement is always linked to the if statement, which jumps out of the loop when the condition is met

Continue:

The purpose of the continue statement is to skip a loop and subsequent statements for the next loop. Continue statements are used only in loop bodies such as for, while, Do-while, and often with an if condition statement to speed up the loop

For example: int i=0;

int a=2;

for (i=0;i<10;i++) {

if (i==a) {

①break;

②continue;

}

System.out.print ("Apple");

}

In the example above, if it is ①, then the loop statement executes 3 times, outputs two apple; if it is ②, the loop executes 10 times and outputs 10 apple

Attention:

1) The break statement does not work for if-else conditional statements.

2) in a multi-layer loop, a break statement jumps out only one layer

Shell-jump out of the loop 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.