Continue parsing of Java

Source: Internet
Author: User

Sometimes it is useful to force a cycle to be repeated early. That is, you may want to continue running the loop, but ignore the statement that repeats the remaining loop body.

The continue statement is a complement to the break statement.

In the while and do while loops, the continue statement causes the control to be transferred directly to the conditional expression of the control loop, and then continues the looping process.

In the For loop, the repeating expression of the loop is evaluated, and then the conditional expression is executed, and the loop resumes execution.

For these 3 loops, any intermediate code will be bypassed.

Class Continue {
public static void Main (String args[]) {
for (int i=0; i<10; i++) {
System.out.print (i + "");
if (i%2 = = 0) continue;
System.out.println ("");
}
}
}

The program uses the% (modulo) operator to verify if the variable i is an even number, and if so, the loop resumes execution without outputting a new row. The results of the program are as follows:

0 1
2 3
4 5
6 7
8 9

Class Continuelabel {
public static void Main (String args[]) {
outer:for (int i=0; i<10; i++) {
for (int j=0; j<10; J + +) {
if (J > i) {
System.out.println ();
Continue outer; }
System.out.print ("" + (I * j));}}
System.out.println ();
}
}

In this example, the continue statement terminates the loop of Count J and continues counting I for the next iteration of the loop. The output of the program is as follows:

0
0 1
0 2 4
0 3 6 9
0 4 8) 12 16
0 5 10 15 20 25
0 6 12 18 24 30 36
0 7 14 21 28 35 42 49
0 8 16 24 32 40 48 56 64
0 9 18 27 36 45 54 63 72 81

For special cases that need to be repeated earlier, the Continue statement provides a structured approach to implementation.

Continue parsing of Java

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.