top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference between continue and Break statements?

+3 votes
509 views

I hope behavior would be same across languages?

posted Jun 3, 2014 by Merry

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+2 votes
 
Best answer

If you want to leave a loop then you can use break and if you want to jump to next iteration then you use continue. See the following flow charts:

Break
Break a Loop

Continue
Continue a Loop

Sample Code

for (i=0; i<5; i++) {
        if (i == 2) 
            break;
       printf("%d ", i);
}
Output: 0 1

for (i=0; i<5; i++) {
        if (i == 2) 
            continue;
       printf("%d  ", i);
}
Output: 0 1 3 4
answer Jun 3, 2014 by Salil Agrawal
+2 votes

continue:

  1. If this statement is used within a loop then, it will skip rest part
    of the loop and continues to execute next iteration of the loop.

break:

  1. If this statement is used within a loop then, it will skip rest part
    of the loop and also skips remaining iterations of the loop.
answer Jun 3, 2014 by Nagaraja Sadar
Similar Questions
+4 votes

What is the difference between <asp:Panel > and <asp:PlaceHolder > in ASP.NET? When should you use one over the other?

+8 votes

Which one is used where and how?

+2 votes

How can I print the longest number in a string?

...