The continue Statement in Java

Haider Ali Feb 02, 2024
The continue Statement in Java

This guide is all about the use of continue statements in Java. What is it? How does it work? When do you need to use this statement? All of this is explained in this short guide. Let’s dive in.

the continue Statement in Java

You will use the continue statement in loops mostly. This statement in Java works somewhat like a break statement. The only difference is that it does not terminate the loop. Instead, it makes the loop run its next iteration without running the code below the continue statement. Take a look at the code snippet we provided below.

public class Main {
  public static void main(String args[]) {
    for (int i = 0; i < 100; i++) {
      if (i % 2 != 0) {
        continue; //  SKip the Iteration If Number IS Odd;
      }
      System.out.print(i + ", ");
    }
  }
}

What will be the outcome of the code? Will it print any odd number? The answer is NO. Because inside the condition, there’s a continue statement which will jump the loop to its next iteration while skipping the whole code down below.

Author: Haider Ali
Haider Ali avatar Haider Ali avatar

Haider specializes in technical writing. He has a solid background in computer science that allows him to create engaging, original, and compelling technical tutorials. In his free time, he enjoys adding new skills to his repertoire and watching Netflix.

LinkedIn

Related Article - Java Statement