Java Continue Statement

🔷 What is the continue statement?

In Java, The continue statement skips the current iteration of a loop and moves to the next iteration.


🔷 Syntax:

continue;

🔷 Where can continue be used?

  • Inside for, while, and do-while loops


📘 Example: Skipping an iteration

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

Output:

i = 1
i = 2
i = 4
i = 5

🔎 Explanation:
When i == 3, the continue statement skips the rest of the loop and jumps to the next value of i.


🔄 Difference between break and continue

Feature break continue
Purpose Exits the loop entirely Skips current iteration only
Affects Entire loop Single iteration
Used in Loops and switch Loops only

Related Posts