Turn Desktop View Off
by Dinesh Thakur Category: Control Structures

In this example, the continue statement is placed in the body of inner for loop. While executing inner for loop, if the condition (m==n) evaluates to true then the continue statement is executed and the remaining statement for displaying values of m and n is skipped and control is transferred to the increment expression (n++) of inner for loop. This increments the value of n by 1 and test condition (n<=2) is evaluated again for this incremented value of n. This process continues. We have used continue statement in this program so that the same value of m and n should not be displayed.

Like the labeled break statement, we also have a labeled continue statement which is usually encountered in the nested loop. The labeled continue statement cause the labeled loop to start a new iteration and terminate the current and future iterations of all the inner loops. The syntax for using the labeled continue statement is

continue label;

The rules for naming label are the same as discussed in the labeled break statement.

//Program to Show Importance of Continue Statement

public class ContinueStatement
    public static void main(String[] args)
        System.out.println("Show importance of Continue statement");
        for(int m=1;m<=3;m++)
                for(int n=1;n<=2;n++)
                         System.out.println("m = "+m+ " n = " + n);

Program To Show Importance of Continue Statement

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles