Java Break and Continue


Break statement in Java:

The break statement is used to come out of the loop immediately and the program control resumes at the next statement following the loop.

Break statement is mainly used with in loop statement, switch and if statements.

Java Break & Contiune

Syntax:-

break; 

Example:-

public class Break 
{  
	public static void main(String[] args) {   
        int i=0;        
        for(i=1; i<=5; i++){      
			System.out.println(i);    
            break;      
        } 
    }    
} 

Continue statement in Java:

When continue statement is used inside a loop, control directly jumps to the beginning of the loop for next iteration, skipping the execution of statements inside loop’s body for the current iteration.

Syntax:-

continue; 

Example:-

public class Continue 
{  
	public static void main(String[] args) {   
        int i=0;        
        for(i=1; i<=5; i++){      
			System.out.println(i);    
            continue;      
        } 
    }    
} 



Onlinetpoint is optimized for basic learning, practice and more. Examples are well checked and working examples available on this website but we can't give assurity for 100% correctness of all the content. This site under copyright content belongs to Onlinetpoint. You agree to have read and accepted our terms of use, cookie and privacy policy.