by Dinesh Thakur

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++)
                    {
                         if(m==n)
                         continue;
                         System.out.println("m = "+m+ " n = " + n);
                    }
            }
    }
}

Program To Show Importance of Continue Statement