What is the difference between a break statement and a continue statement

A break statement results in the termination of the statement to which it applies (switch,for, do, or while). A continue statement is used to end the current loop iteration andreturn control to the loop statement.

Showing Answers 1 - 19 of 19 Answers

Richa

  • Sep 8th, 2005
 

break statement  
A statement that terminates the current loop iteration and causes execution to break out of a loop. 
 
continue statement  
A statement that terminates the current loop iteration and persists the loop with the next iteration.

  Was this answer useful?  Yes

When you are dealing with loops in your code (like for , while , do-while not if or switch)
continue will go back and increase the loop counter and start executing. all the statements below the continue in that loop would be skipped.

In case of break we exit out of the loop and go ahead.

The break keyword halts the execution of the current loop and forces control out of the loop.

The continue is similar to break, except that instead of halting the execution of the loop, it starts the next iteration.

  Was this answer useful?  Yes

Arvindanathan

  • Dec 3rd, 2013
 

Code
  1. public class BreakAndContinue

  2. {

  3.         public static void main(String[] args)

  4.         {

  5.  

  6.                 for (int i = 0; i < 100; i++)

  7.                 {

  8.                         if(i==10)

  9.                         {

  10.                                 break;

  11.                         }

  12.                         if(i==5)

  13.                         {

  14.                                 continue;

  15.                         }

  16.                         System.out.println("I : "+i);          

  17.                 }      

  18.         }

  19.  

  20. }

  21. //Output :

  22. I : 0

  23. I : 1

  24. I : 2

  25. I : 3

  26. I : 4

  27. I : 6

  28. I : 7

  29. I : 8

  30. I : 9

  31.  

  32.  



Dhiman Kumar

  • Feb 1st, 2016
 

Similarity: Both break and continue are jumping statements. Difference: The break statement terminates the entire loop execution whereas continue statements single pass of the loop.

  Was this answer useful?  Yes

komalnk

  • Mar 1st, 2016
 

A break statement results in the termination of the statement to which it applies (switch,for, do, or while). A continue statement is used to end the current loop iteration and return control to the loop statement.

  Was this answer useful?  Yes

sandra

  • Jun 13th, 2016
 

What happens if break is not used in switch statement?

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions