Using break with nested loops : Break « Language Basics « C# / C Sharp






Using break with nested loops

Using break with nested loops
/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
// Using break with nested loops.  
 
using System; 
 
public class BreakNested {  
  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.");  
  }  
}

           
       








Related examples in the same category

1.the break statementthe break statement
2.Find the smallest factor of a valueFind the smallest factor of a value