Wednesday, May 23, 2012

C# break Statement


C# break Statement

The break statement in c# is used to terminate a loop, if a break statement is placed in a loop then the loop execution is terminated on reaching the break statement, control is transferred to the next executable statement which is placed after the loop.

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

In the above example when I values is greater than 5 the break statement is executed and control in transferred to the next statement outside the loop, the output in this case will be

1
2
3
4
5
Statement after the for Loop


That’s it, we have evaluated the use of the break statement.



Related Post


Search Flipkart Products:
Flipkart.com

No comments: