Put Switch statement inside a for loop : Switch : Statement C# Examples


C# Examples » Statement » Switch »

 

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;                                            
                  }
            }
      }
}
    
   
  
   



Output

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


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Statement
» Switch