Csharp for loop break

Example shows the way one could break and come out of a for loop.

Example:

using System; 

class ExampleForBreakClass
{
  public static void Main()
  {
    int counter; 

    for(counter = 1; counter <= 5; counter = counter++)
     {
        Console.WriteLine("Display counter: " + counter); 

         if( counter == 3)
             break;
     }
  }
}

Output:
Display counter: 1
Display counter: 2
Display counter: 3

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>