Continue statement in Java

The continue statement in Java is used to skip the current iteration of a loop and continue with the next iteration. When a continue statement is encountered in a loop, the rest of the statements in the current iteration are skipped, and the loop continues with the next iteration.


Here's an example that uses the continue statement to skip even numbers when printing the numbers from 1 to 10:

for (int i = 1; i <= 10; i++) {
	if (i % 2 == 0) {
		continue; 
 	} 
 	System.out.println(i); 
 }
 


In this example, the loop runs 10 times, printing the odd numbers from 1 to 10. If i is even (i.e., i % 2 == 0), the continue statement is executed, and the rest of the statements in the current iteration are skipped. The loop then continues with the next iteration.


Here's another example that uses the continue statement to skip numbers that are divisible by 3:


for (int i = 1; i <= 10; i++) {
	if (i % 3 == 0) {
		continue; 
	}
	System.out.println(i); 
}


In this example, the loop runs 10 times, printing the numbers from 1 to 10 that are not divisible by 3. If i is divisible by 3 (i.e., i % 3 == 0), the continue statement is executed, and the rest of the statements in the current iteration are skipped. The loop then continues with the next iteration.


In conclusion, the continue statement is a useful control flow statement that allows you to skip the current iteration of a loop and continue with the next iteration. It's commonly used in combination with an if statement to skip specific iterations based on some condition.