0
0
Javaprogramming~5 mins

Continue statement in Java

Choose your learning style9 modes available
Introduction
The continue statement helps skip the current step in a loop and move to the next one. It lets you ignore some steps without stopping the whole loop.
When you want to skip processing certain items in a list but keep checking the rest.
When filtering data inside a loop and ignoring unwanted values.
When you want to avoid errors by skipping invalid inputs during looping.
When you want to jump over some steps in a loop based on a condition.
When you want to make your loop cleaner by avoiding nested if-else blocks.
Syntax
Java
continue;
The continue statement is used inside loops like for, while, or do-while.
When continue runs, the loop skips the rest of the current iteration and moves to the next one.
Examples
This loop prints numbers 1 to 5 but skips 3 because of continue.
Java
for (int i = 1; i <= 5; i++) {
    if (i == 3) {
        continue;
    }
    System.out.println(i);
}
This while loop skips printing the number 2.
Java
int i = 0;
while (i < 5) {
    i++;
    if (i == 2) {
        continue;
    }
    System.out.println(i);
}
Sample Program
This program prints numbers from 1 to 5 but skips number 3 using continue.
Java
public class ContinueExample {
    public static void main(String[] args) {
        for (int i = 1; i <= 5; i++) {
            if (i == 3) {
                continue;
            }
            System.out.println("Number: " + i);
        }
    }
}
OutputSuccess
Important Notes
Using continue can make loops easier to read by skipping unwanted steps early.
Be careful not to create infinite loops by skipping the part that changes the loop variable.
Continue only affects the current loop iteration, not the whole loop.
Summary
The continue statement skips the rest of the current loop step and moves to the next.
It is useful to ignore certain values or conditions inside loops.
Use continue inside for, while, or do-while loops.