Using break with nested loops : Break « Statement « C# / CSharp Tutorial






using System; 
 
class MainClass {  
  public static void Main() {  
  
    for(int i=0; i<3; i++) {  
      Console.WriteLine("Outer loop count: " + i);  
      Console.Write("    Inner loop count: "); 
 
      int t = 0;             
      while(t < 100) {  
        if(t == 10) 
            break; // terminate loop if t is 10  
        Console.Write(t + " ");  
        t++; 
      }  
      Console.WriteLine();  
    }  
    Console.WriteLine("Loops complete.");  
  }  
}
Outer loop count: 0
    Inner loop count: 0 1 2 3 4 5 6 7 8 9
Outer loop count: 1
    Inner loop count: 0 1 2 3 4 5 6 7 8 9
Outer loop count: 2
    Inner loop count: 0 1 2 3 4 5 6 7 8 9
Loops complete.








4.7.Break
4.7.1.Using break to exit a for loop
4.7.2.Find the smallest factor of a value
4.7.3.Using break with nested loops
4.7.4.Using break to exit a do-while loop
4.7.5.Use break with a foreach.