Difference between a break statement and a continue statement
Hi Friends
What is the difference between a break statement and a continue statement?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Oct 19, 2012, 10:26 PM EDT
For eg
for (int i=0;i<10;i++)
{
Console.WriteLine(i);
If (i==3)
break;
Console.WriteLine(i);
}
This will print
0
0
1
1
2
2
3
once i value is 3, it will go inside if statement and break will executed. So there wont be no more iteration.
But in case if its continue.
for (int i=0;i<10;i++)
{
Console.WriteLine(i);
If (i==3)
continue;
Console.WriteLine(i);
}
This will print
0
0
1
1
2
2
3
4
4
5
5
6
6
7
7
8
8
9
9
In this 3 is printed only once. Thats because when it goes continue statement, it will skip the remaining piece of code. So the second print statment is not executed.
Satyapriya NayakRank #47 · 31.5K reputationPosted Oct 19, 2012, 11:09 PM EDT
Please refer the below links
http://www.dotnetperls.com/break
http://www.dotnetperls.com/continue
Thanks
Neha SharmaRank #569 · 4.3K reputationPosted Oct 19, 2012, 11:13 PM EDT
Break : leaves a loop
Continue : jumps to the next iteration.
If it helps you mark it as answer.
VulpesRank #55 · 29.2K reputationPosted Oct 20, 2012, 2:36 AM EDT
However, they also have labelled forms (a bit like goto in other languages) which enable you to break out of continue with loops other than the closest one.