Home » Java Basics » break/continue statement » Continue Statement

About Byron Kiourtzoglou

Byron Kiourtzoglou
Byron is a master software engineer working in the IT and Telecom domains. He is an applications developer in a wide variety of applications/services. He is currently acting as the team leader and technical architect for a proprietary service creation and integration platform for both the IT and Telecom industries in addition to a in-house big data real-time analytics solution. He is always fascinated by SOA, middleware services and mobile development. Byron is co-founder and Executive Editor at Java Code Geeks.

Continue Statement

In this example we shall show you how to use the continue statement. The continue statement skips the current iteration of a for, while , or do-while loop. In the example the continue statement is used when checking an array’s elements, as described:

  • Create a for statement with an int index from 0 up to an int array length, that checks the elements of the array.
  • When an element divided to 2 returns 0, then the continue statement is called that skips the current iteration,

as described in the code snippet below.  

package com.javacodegeeks.snippets.basics;

public class ContinueStatement {

	public static void main(String[] args) {

		int array[] = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

		System.out.println("Printing all odd numbers");
		
		for (int i = 0; i < array.length; i++) {
			if (array[i] % 2 ==0)
				continue;
			else
				System.out.print(array[i] + " ");
		}

	}

}

Output:

Printing all odd numbers
1 3 5 7 9 

  
This was an example of how to use the continue statement in Java.

(No Ratings Yet)
Start the discussion Views Tweet it!

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

 

Leave a Reply

avatar
  Subscribe  
Notify of