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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Oct 20, 2012, 6:36 AM
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.
Neha SharmaPosted Oct 20, 2012, 3:13 AM
Break : leaves a loop
Continue : jumps to the next iteration.
If it helps you mark it as answer.
Satyapriya NayakPosted Oct 20, 2012, 3:09 AM
Please refer the below links
http://www.dotnetperls.com/break
http://www.dotnetperls.com/continue
Thanks
Santhosh Kumar JayaramanPosted Oct 20, 2012, 2:26 AM
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.