Results 1 to 4 of 4

Thread: switch

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    switch

    Heya;

    Im a newbie in C# and Im trying to loop 5 times in a console app. However the program exits on the second entry. The problem seems to be the For control . Anyone can point out to me the mistake pls/



    Code:
    namespace ConsoleSwitch
    {
        class Program
        {
            static void Main(string[] args)
            {
                int x;
                string colour,str;
                string Blue,Red, Yellow ;
                Console.WriteLine("Enter the primary colours colour");
                colour = Console.ReadLine();
                for (x = 1; x <= 5; x++) ;
    
                switch (colour)
                {
                    case  "Blue":
                        Console.WriteLine("Blue is a primary colour");
                        //str = Console.ReadLine();
                        break;
    
                    case  "Red":
                        Console.WriteLine("Red is a primary colour");
                        //str = Console.ReadLine();
                        break;
    
                    case "Yellow":
                        Console.WriteLine("Yellow is a primary colour");
                        break;
                    case "White":
                        Console.WriteLine("White is a primary colour");
                        break;
                    case "Black":
                        Console.WriteLine("Black is a primary colour");
                        break;
                    
                    default:
                        Console.WriteLine("Colour is NOT a primary colour");
                        //str = Console.ReadLine();
                        break;
                        
                 } //end of switch
                str = Console.ReadLine();
              } //end of For
            
           }
    Last edited by angelica; Jan 3rd, 2009 at 11:36 PM.
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width