Skip to content
C

continue

The continue statement skips the rest of the current loop iteration and jumps straight to the next one, without exiting the loop entirely.


1. What is the continue Statement?

The continue statement skips the rest of the current loop iteration and jumps straight to the next one, without exiting the loop entirely.

2. Why is it used?

Sometimes you want to skip just one specific case while still continuing the loop for everything else — like skipping negative numbers while still processing the rest of a list.

3. Real-Life Example

Think of a teacher calling out roll numbers for a fitness test, but skipping students who are absent that day — the teacher doesn't stop the whole test, they just move on to the next name.

4. Syntax

java
for (...) { if (condition) { continue; // skips to next iteration } // remaining code in the loop }

5. Example Program

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

Output:

1
2
4
5

6. Key Points to Remember

  • continue skips only the current iteration; the loop itself keeps running.
  • It's different from break, which stops the loop entirely.
  • Overusing continue in complex loops can sometimes make code harder to follow — use it thoughtfully.