Mega Code Archive

 
Categories / C# Tutorial / Statement
 

Put Switch statement inside a for loop

using System; class MainClass {    static void Main()    {       for (int x = 1; x < 6; x++)       {          switch (x)                                  {             case 2:                                        Console.WriteLine("x is {0} -- In Case 2", x);                break;                                   case 5:                                        Console.WriteLine("x is {0} -- In Case 5", x);                break;                                   default:                                       Console.WriteLine("x is {0} -- In Default case", x);                break;                                }       }    } } x is 1 -- In Default case x is 2 -- In Case 2 x is 3 -- In Default case x is 4 -- In Default case x is 5 -- In Case 5