Home Java Docker
Home     Java

Java Topic

What is Java
History of Java
Freature of Java
Difference Between Java & C++
Java Environment Set Up
Java Hello World Program & its Internal Process
Java Hello World Program
JDK, JRE and JVM
Java Variables
Java Data Types & Unicode System
Java Operators
Java Keywords
Java Control Statements
Java if else
Java switch
Java for loop
Java While loop
Java Do While loop
Java break
Java continue
Java Oops Concept
Java Object & Class
Java Method
Java Constructor
Java Static Keyword
Java this Keyword
Java Inheritance
Java Hybrid Inheritance
Aggregation(HAS-A)
Java Polymorphism
Java method overloading
Java method overriding
Java Runtime polymorphism
Java Dynamic Binding
Super keyword
Final keyword
Difference Between method overloading and method overriding
Java Abstraction
Java Interface
Abstract class vs Interface
Java Encapsulation
Java Package
Java Access Modifiers
covariant return type
Instance initializer block
Java instanceof operator
Object Cloning in Java
Wrapper classes in Java
Java Strictfp Keyword
Recursion in Java
Java Command Line Arguments
Difference between object and class
Java String
Java String Class
Java Immutable String
Java Immutable Class
String Buffer
String Builder
String Buffer vs String
String Builder vs String Buffer
String Tokenizer in Java
Java Array
Java Exceptions Handling
Java Try-Catch block
Java Multiply Catch Block
Java Finally Block
Java Throws Keyword
Java Throw Keyword
Java Exception Propagation
Java Throw vs Throws
Final vs Finally vs Finalize
Exception Handling With Method Overridding
Java Multithreading
Lifecycle and States of a Thread in Java
How to create a thread in Java
Thread Scheduler in Java
Sleeping a thread in Java
Calling run() method
Joining a thread in Java
Naming a thread in Java
Thread Priority
Daemon Thread
Thread Pool
Thread Group
Shutdown hook
Multitasking vs Multithreading
Garbage Collection
RunTime Class
Java Synchronization
Synchronized block in Java
Static Synchronization in Java
Deadlock in Java
Inter Thread Communication in Java
Interrupting Thread in Java
Reentrant Monitor in Java
Java Applet
Animation in Applet
EventHandling in Applet
Display image in Applet
Displaying Graphics in Applet
Parameter in Applet
Java 8 Features
Java Lambda Expressions
Method References
Functional Interfaces
Java 8 Stream
Base64 Encode Decode
Default Method
for Each() Method
Collectors class
String Joiner Class
Optional Class
JavaScript Nashron
Parallel Array Sort
Type Interface
Parameter Reflection
Type and Repeating Annotations
JDBC Improvements

Java continue statement

The continue statement is used in loop control structures when you need to immediately jump to the next iteration of the loop. It can be used with either a for loop or a while loop.

To continue the loop, the Java continue statement is used. It continues the program's current flow while skipping the remaining code at the specified condition. In the case of an inner loop, it only continues the inner loop.


In programming languages, the continue statement is frequently used inside loop control structures. When a continue statement is encountered within the loop, the control jumps directly to the beginning of the loop for the next iteration rather than executing the statements of the current iteration. When we want to skip a specific condition and continue with the rest of the execution of program then we use the continue statement. The Java continue statement can be used in any type of loop, but it is most commonly found in for, while, and do-while loops.

Syntax

 continue; 

When a loop encounters a continue statement, that iteration is skip in loop



 //  continue statement using for loop  
public class Student {  
	public static void main(String[] args) {  
        for (int i = 1; i < 10; i++) {
            if (i == 5){
            	 System.out.println();     // this print statement to just show skip value   
                  continue; // use continue keyword to skip the current iteration
            }
            System.out.println(i);
        }     
    }  
}

Output:

1  
2 
3 
4 
  
5 
6 
7 
8 
9 



continue statement with for each loop

 // continue statement with labeled for loop. we use return instead of continue 
import java.util.Arrays;
import java.util.List;
public class Student {  
	public static void main(String[] args) {  
		List<Integer> numberList = Arrays.asList(20,31,41,50,69,80);
		numberList.forEach( x-> {
		    if( x%2 == 0) {
		        return; // only skips this iteration.
		    }
		    System.out.println(x);
		});   
    }  
}

Output:

31 
41 
69 

continue statement with while loop

 // continue statement with while  loop  
public class Student {  
	public static void main(String[] args) {  
        int i=1;  
        while(i<=5){  
	        if(i==4){  
	            i++;  
	            continue;
	        }  
	        System.out.println(i);  
	        i++;           
          }   
       }  
}

Output:

1 
2  
3 
5 

continue statement with do.. while loop

 // continue statement with do.. while  loop  
public class Student{
    public static void main(String[] args){  
        int i=1;  
        do {
            if(i==4){  
                i++;  
                continue;
            }  
            System.out.println(i);  
            i++;
        } while (i<=5);  
    }
}

Output:

1 
2  
3 
5 

Java Oops Next »
« Perv Next »


Post your comment





Read Next Topic
Java Tutorial - Topic
Java Control Statements
Java if else
Java switch
Java for loop
Java While loop
Java Do While loop
Java break
Java continue
Read Other Java Chapter
Java Topic
Java Basic Tutorial
Java Control Statements
Java Classes & Object
Java Inheritance
Java Polymorphism
Java Abstraction
Java Encapsulation
Java OOPs Miscellaneous
Java Array
Java String
Java Exception Handling
Java Multithreading
Java Synchronization
Java Applet
Java 8 Features
Java 9 Features
Java Collection
Java Mcq
Java Interview Question
Tools
  

Useful Links

  • Home
  • Blog
  • About us
  • Contact Us
  • Privacy policy

Contact Us

Police Colony
Patna, Bihar
India

Email:

About DockerTpoint


India's largest site for Programming Tutorial as well as BANK, SSC, RAILWAY exam
and Campus placement preparation.