Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this:

C#
static void Main(string[] args)
       {
           //TimePlanner timePlanner = new TimePlanner();
           //LoginDetails loginDetails = new LoginDetails();

           IBotAction botAction;
           //string value;
           Console.WriteLine("choose the option you want to see");
           Console.WriteLine("\n1.Type timePlanner - here you can see your tasks ");
           Console.WriteLine("\n2.Type  loginDetails - Here you can see the log in data of the client");
           Console.WriteLine("\nType here your choice");
           string input = Console.ReadLine();
           while (true)
           {
               //if (input == "exit")
               //{


                   switch (input)
                   {
                       case "timePlanner":
                           // Console.WriteLine("You have choosen for Time Planner");
                           botAction = new TimePlanner();
                           botAction.ActionName();
                           break;
                       case "loginDetails":
                           //Console.WriteLine("You have choosen for Log in Details");
                           botAction = new LoginDetails();
                           botAction.ActionName();
                           break;


                       default:
                           break;
                   }
               //}
               //break;


           }


           Console.ReadKey();
       }


but the problem is that the output string continued, and doesnt stop after first output

Thank you
Posted
Comments
CHill60 20-Feb-15 7:49am    
You are not breaking out of the while loop - the "break" statements that are not commented out are within the switch statement not the loop
[no name] 20-Feb-15 7:55am    
Thank you, I posted my my correction

You have a never ending loop
C#
while (true)
...

This will cause the program to repeat the switch statement again and again and again and again and again and again and again...
 
Share this answer
 
As per my comment, you are not breaking out of that (infinite) while loop.

Try something like this instead:
C#
Console.WriteLine("\nType here your choice");
Console.WriteLine("\nOr type 'Exit' to end");
while (true)
{
    string input = Console.ReadLine();
    if (input.ToLower() == "exit")
    {
        break;
    }
    switch (input)
etc...
 
Share this answer
 
Comments
[no name] 20-Feb-15 8:24am    
thank you, see my update
CHill60 20-Feb-15 8:29am    
See my comments to your update
[no name] 20-Feb-15 9:33am    
ok, thank you
Like this:

C#
hile (true)
            {
                //if (input == "exit")
                //{


                    switch (input)
                    {
                        case "timePlanner":
                            // Console.WriteLine("You have choosen for Time Planner");
                            botAction = new TimePlanner();
                            botAction.ActionName();
                            break;
                        case "loginDetails":
                            //Console.WriteLine("You have choosen for Log in Details");
                            botAction = new LoginDetails();
                            botAction.ActionName();
                            break;
                        default:
                            break;
                    }
                    break;
                //}
                //break;


            }



            Console.ReadKey();
        }



I have it now like this:

C#
while (true)
           {
               //if (input == "exit")
               //{
               string input = Console.ReadLine();
               if (input.ToLower() == "exit")
               {
                   break;
               }

                   switch (input)
                   {
                       case "timePlanner":
                           // Console.WriteLine("You have choosen for Time Planner");
                           botAction = new TimePlanner();
                           botAction.ActionName();
                           break;
                       case "loginDetails":
                           //Console.WriteLine("You have choosen for Log in Details");
                           botAction = new LoginDetails();
                           botAction.ActionName();
                           continue;
                       case "Q":
                           break;
                       default:
                           break;
                   }
                   break;
               //}
               //break;


           }



           Console.ReadKey();
       }


but the problem is that I only can type one option
 
Share this answer
 
v2
Comments
CHill60 20-Feb-15 7:56am    
By posting this as a solution you have made your question drop out of the list of unanswered questions. If you need to improve your post use the "Improve question" link
CHill60 20-Feb-15 7:59am    
Ah - I've now spotted the subtle difference. However this means it will run once and once only, therefore there is no need for the while loop at all.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900