The continue statement in Java is used to skip the current iteration of a loop and move directly to the next iteration.
// Basic syntax of continue statement
continue;
// Skip number 5 using continue
public class ContinueDemo {
public static void main(String[] args) {
for(int i = 1; i <= 10; i++) {
if(i == 5) {
continue;
}
System.out.println(i);
}
}
}
1 2 3 4 6 7 8 9 10
When the loop variable becomes 5, the continue statement skips printing and moves to the next iteration.