JavaBeat

  • Home
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Privacy
  • Contact Us

Continue Statement in Java

March 17, 2014 by Krishna Srinivasan Leave a Comment

This example shows how to use the continue statement in Java programming. In my previous example I have explained about the break statement which is useful for termination the look and come out of it. However, in certain cases one might want to terminate only the current iteration and skip to the next iteration. In that scenario, one might fine continue statement is very useful. Here I have written a very simple example to explain the continue statement and its usage. If you have any questions, please write it in the comments section.

[code lang=”java”]
package javabeat.net.core;

import java.util.ArrayList;
/**
* Continue statement example
* @author krishna
*
*/
public class ContinueExample {
public static void main(String args[]){
ArrayList<String> days = new ArrayList<String>();
days.add("Monday");
days.add("Tuesday");
days.add("Wednesday");
days.add("Thursday");
days.add("Friday");
days.add("Saturday");
days.add("Sunday");
for (String str : days){
if (str.equals("Wednesday")){
System.out.println("Today is Wednessday!!!. I am skiping it");
continue;
}
System.out.println("Day : " + str );
}

}
}
[/code]

Output

[code]
Day : Monday
Day : Tuesday
Today is Wednessday!!!. I am skiping it
Day : Thursday
Day : Friday
Day : Saturday
Day : Sunday
[/code]

Filed Under: Java Tagged With: Core Java

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

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

Follow Us

  • Facebook
  • Pinterest

As a participant in the Amazon Services LLC Associates Program, this site may earn from qualifying purchases. We may also earn commissions on purchases from other retail websites.

JavaBeat

FEATURED TUTORIALS

Answered: Using Java to Convert Int to String

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Copyright © by JavaBeat · All rights reserved