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 - 7 of 7 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. span style="color: #ff0000;">"I : "+i);        

  2.                 }      

  3.         }

  4.  

  5. }

  6. //Output :

  7. I : 0

  8. I : 1

  9. I : 2

  10. I : 3

  11. I : 4

  12. I : 6

  13. I : 7

  14. I : 8

  15. I : 9

  16.  

  17.  



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