Create a nested for loop in CSharp

Description

The following code shows how to create a nested for loop.

Example


using System; /*from w ww .  ja v a 2 s. com*/
     
public class MainClass {     
   static void Main(string[] args) 
   { 
      // This loop iterates through rows 
      for (int i = 0; i < 100; i+=10) 
      { 
         // This loop iterates through columns 
         for (int j = i; j < i + 10; j++) { 
                   Console.Write(" " + j); 
         } 
         Console.WriteLine(); 
       } 
   }  
}

The code above generates the following result.





















Home »
  C# Tutorial »
    C# Language »




C# Hello World
C# Operators
C# Statements
C# Exception