Wednesday, May 23, 2012

C# break Vs continue Statement


C# break Vs continue Statement

The break statement in c# completely terminates the execution of the current loop, and processes the statement which is placed immediately after the loop.

The continue statement just skips the current iteration of the loop and processes the next iteration in the loop.

Break Statement
for (int i = 1; i <= 10; i++)
{
  
 if (i == 5)
   {
    
 break;
   }
  
 //
   Response.Write(i.ToString() + "<br>");
}
//
Response.Write("Statement after the for Loop");

Output
1
2
3
4
Statement after the for Loop

Continue Statement
for (int i = 1; i <= 10; i++)
{
   if (i == 5)
   {
     continue;
   }
   //
   Response.Write(i.ToString() + "<br>");
}
//
Response.Write("Statement after the for Loop");

Output
1
2
3
4
6
7
8
9
10

Statement after the for Loop 


That’s it, we have seen the difference between break and continue statements in c#


Related Post
C# break Statement
C# continue Statement
C# goto Statement
C# return Statement
C# break Vs continue Statement


Search Flipkart Products:
Flipkart.com

No comments: