break/continue statement

Continue Java Statement

1. Continue Java Statement

In this example, we shall show you how to use the continue keyword statement in Java.

The continue statement skips the current iteration of a for, while, or do-while loop and it continues the current flow of the program. In case of an inner loop, the continue statement continues only the inner loop.

In this example, the continue statement is used when checking an array’s elements, as described below:

Continue Java
  • 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:  

Java

Output

1
2
Printing all odd numbers
1 3 5 7 9

3. Labeled continue

Let’s say you have the below example:

Java

If we just write the continue statement, then this will print 0 and 0, 0 and 0 and 2 etc. But if we wanted to continue the outer loop we could do the following.

Java

Now the output will be 0 and 0, 1 and 0, 2 and 0 etc.

This was an example of how to use the continue statement, which is an essential part of the Java syntax.

2. Download the source code

That was an example of how to use the continue keyword in Java.

Download
You can download the full source code of this example here: Continue Java Statement

Last updated on Apr. 22nd, 2020

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 ....
I agree to the Terms and Privacy Policy

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.
Subscribe
Notify of
guest


This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button