2 Replies - 724 Views - Last Post: 16 January 2014 - 07:09 PM Rate Topic: -----

#1 bran3w   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 24-October 13

Simple Console Menu Question

Posted 16 January 2014 - 05:20 PM

I am trying to write a simple console menu. I think I have it down, but I'm not sure how to return to a previous menu. I tried using return; but that did not work. If someone could help me out on the best way to do this, that would be awesome. Thanks for your time.
while (input != "6")
                {
                    if (input == "1")
                    {
                        Console.WriteLine("Press 1 for, View  ");
                        Console.WriteLine("Press 2 for, Add  ");
                        [b]Console.WriteLine("Press 3 for, Return to previous menu");[/b]
                        string input2 = Console.ReadLine();
                        while (input2 != "4")
                        {
                           if (input2 == "1")
                           {}
                            if (input2 == "2")
                            {}
                              [b]  if (input2 == "3")
                                {
                                    return;
                                   }
[/b]
                        }
                      }
                  
                    
                      if (input == "2")
                    {
                        Console.WriteLine("hey");

                          }
                  
                    }
                      if (input == "3")
                      {
                        Environment.Exit(0);
                      }


This post has been edited by JackOfAllTrades: 16 January 2014 - 06:00 PM
Reason for edit:: Fixed code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Simple Console Menu Question

#2 andrewsw   User is offline

  • no more Mr Potato Head
  • member icon

Reputation: 6957
  • View blog
  • Posts: 28,696
  • Joined: 12-December 12

Re: Simple Console Menu Question

Posted 16 January 2014 - 06:32 PM

break, instead of return, will break out of the while loop. return will return from the method that this code is in.

This post has been edited by andrewsw: 16 January 2014 - 06:34 PM

Was This Post Helpful? 1
  • +
  • -

#3 bran3w   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 24-October 13

Re: Simple Console Menu Question

Posted 16 January 2014 - 07:09 PM

Thanks I will try it when I get back at it. Thank you Andrew!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1