I need help with a loop in a menu
I need a menu that loops until you choose to quit and that writes something if you give a wrong response but allows you to try again
13 Replies
You never change the choice inside of the loop
how would i do it instead+
?
something like that
im unfamiliar with do
Rewrite it to a normal while loop then
Or familiarize yourself with it
they keep printing endlessly and i have no idea how to make it possible to be able to return to the start
Like this
Notice how
choice
changes inside of the loop
If it never changes, then there can be no way for the loop to stopi already know i did the structure of the do wrong
Console.WriteLine("This is a menu test");
Console.WriteLine("there are (4) options");
Console.WriteLine("");
Console.WriteLine("Start (1) ");
Console.WriteLine("Help (2) ");
Console.WriteLine("Exit (3)");
string choice = Console.ReadLine();
do {
choice = Console.ReadLine();
} while (choice != "quit");
{
if (choice == "1")
{
//real code goes in here
}
if (choice == "2") { //Some kind of text that tells you what to do Console.WriteLine("What you have to do"); } if (choice == "3") { //Exit Console.WriteLine("bye"); return; } else { Console.WriteLine("That is not an answer"); } }
if (choice == "2") { //Some kind of text that tells you what to do Console.WriteLine("What you have to do"); } if (choice == "3") { //Exit Console.WriteLine("bye"); return; } else { Console.WriteLine("That is not an answer"); } }
That is not how a do while loop works
Also, $code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/If you want to use just a while loop, sure, do that
But, again, change the choice inside of the loop
thanks
btw i think i have forgoten about all the public/private and inside/outside rules