Java keyword break and continue

Source: Internet
Author: User

The Break keyword

Break is used primarily in loop statements or switch statements to jump out of the entire block of statements.

Break jumps out of the innermost loop, and continues execution of the statement below the loop.

Grammar

The use of break is simple, which is a statement in the loop structure:

Break

Instance
public class Test {public static void main (String args[]) {int [] numbers = {10, 20, 30, 40, 50};         for (int x:numbers) {if (x = =) {break;         } System.out.print (x);      System.out.print ("\ n"); }   }}

The results of the above example compilation run as follows:

10 20

Continue keywords

The Continue is suitable for any loop control structure. The function is to let the program jump immediately to the next iteration of the loop.

In the For loop, the continue statement causes the program to jump immediately to the UPDATE statement.

In the while or Do...while loop, the program immediately jumps to the judgment statement of the Boolean expression.

Grammar

Continue is a simple statement in the loop body:

Continue

Instance
public class Test {public static void main (String args[]) {int [] numbers = {10, 20, 30, 40, 50};         for (int x:numbers) {if (x = =) {continue;         } System.out.print (x);      System.out.print ("\ n"); }   }}

The results of the above example compilation run as follows:

10 20 40 50

Java keyword 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.