GeekInterview.com
Series: Subject: Topic:
Question: 2046 of 2110

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.
Asked by: Interview Candidate | Asked on: Sep 8th, 2005
Showing Answers 1 - 4 of 4 Answers
Richa

Answered On : 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.

  
Login to rate this answer.
Mithun Challa

Answered On : Jan 6th, 2008

View all answers by Mithun Challa

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.

Yes  2 Users have rated as useful.
  
Login to rate this answer.
Shambhu Kumar

Answered On : May 7th, 2008

View all answers by Shambhu Kumar

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.

  
Login to rate this answer.
Arvindanathan

Answered On : 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.  

Yes  1 User has rated as useful.
  
Login to rate this answer.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.