continue statement


Java continue statement is used in loop control structure when we immediately need to jump to the next iteration of the loop.

It is used to continue the current flow of the program while skipping the remaining code of the loop after the continue statement.

It can be used with for loop or while loop only.

Note: In case of inner loop, it continues to execute in the inner loop.


Syntax:

// loop statements
continue
// code to be skipped

Example:

public class ContinueExample
{
    public static void main (String[] args)
    {
        for(int i = 1; i <= 5; i++)
        {
            if(i == 4)
            {
                continue;
            }
            System.out.println(i);
        }
    }
}

Output:

1
2
3
5