Continue Statement in Java

Sometimes it is needed to go to iteration part before even completing the whole block of statements in the loop. Then continue is useful.

Example: suppose we need to develop a code where we will print only the odd numbers from 1 to 10

So conitnue skips the further statements to execute and jumps to the next iteration of the loop.

public class ContinueDemo {

	public static void main(String[] args) {

		for(int i = 0; i<=10; i++){
			System.out.print(i+" ");
Try It

In the above code, when the process encounters continue, it doesn’t execute the print statement. Instead it goes back to the iteration process.

The output will be:

1 3 5 7 9

Next > < Prev
Scroll to Top