Using break to exit a for loop : Break : Statement C# Examples


C# Examples » Statement » Break »

 

Using break to exit a for loop









    
using  System;  
  
class  MainClass  {    
    public  static  void  Main()  {    
  
        //  use  break  to  exit  this  loop  
        for(int  i=-10;  i  <=  10;  i++)  {    
            if(i  >  0)  break;  //  terminate  loop  when  i  is  positive  
            Console.Write(i  +  "  ");    
        }    
        Console.WriteLine("Done");    
    }    
}
    
   
  
   



Output

-10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 Done


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Statement
» Break