C
C#11mo ago
HD-Fr0sT

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
No description
13 Replies
Angius
Angius11mo ago
You never change the choice inside of the loop
HD-Fr0sT
HD-Fr0sTOP11mo ago
how would i do it instead+ ?
Angius
Angius11mo ago
string choice;
do {
choice = Console.ReadLine();
} while (choice != "quit");
string choice;
do {
choice = Console.ReadLine();
} while (choice != "quit");
something like that
HD-Fr0sT
HD-Fr0sTOP11mo ago
im unfamiliar with do
Angius
Angius11mo ago
Rewrite it to a normal while loop then Or familiarize yourself with it
HD-Fr0sT
HD-Fr0sTOP11mo ago
they keep printing endlessly and i have no idea how to make it possible to be able to return to the start
Angius
Angius11mo ago
Like this Notice how choice changes inside of the loop If it never changes, then there can be no way for the loop to stop
HD-Fr0sT
HD-Fr0sTOP11mo ago
No description
HD-Fr0sT
HD-Fr0sTOP11mo ago
i 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"); } }
Angius
Angius11mo ago
That is not how a do while loop works Also, $code
MODiX
MODiX11mo ago
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/
Angius
Angius11mo ago
If you want to use just a while loop, sure, do that But, again, change the choice inside of the loop
string choice = Console.ReadLine();
while (choice != "quit")
{
choice = Console.ReadLine(); // see? The choice can now *actually* become "quit"
}
string choice = Console.ReadLine();
while (choice != "quit")
{
choice = Console.ReadLine(); // see? The choice can now *actually* become "quit"
}
HD-Fr0sT
HD-Fr0sTOP11mo ago
thanks btw i think i have forgoten about all the public/private and inside/outside rules
Want results from more Discord servers?
Add your server