C
C#16mo ago
monkeyoohlala

✅ I need to put an invalid choice in my program

I need to make the program repeat if they did not input a valid response of yes or no
22 Replies
phaseshift
phaseshift16mo ago
Do a loop then
monkeyoohlala
monkeyoohlala16mo ago
is there a easier way? do a loop kind of broad how do I do this if response == yes continue to the while loop? what kind of loop do I do?
Angius
Angius16mo ago
A while loop, for example
while (input is incorrect)
{
ask for input again
}
while (input is incorrect)
{
ask for input again
}
monkeyoohlala
monkeyoohlala16mo ago
else if (Response != "yes" && Response != "no") { Console.WriteLine("Invalid Choice"); break; // right here how do I get it to go back to the beginning of the loop? Console.ReadLine(); } I tried break and continue and it did not work
phaseshift
phaseshift16mo ago
Break stops the loop. Continue goes to the top of the loop
Angius
Angius16mo ago
Well else if is not a loop
monkeyoohlala
monkeyoohlala16mo ago
it is inside a loop
Angius
Angius16mo ago
Ah, my bad, seems you already have some loops in that chunk of code Yeah
monkeyoohlala
monkeyoohlala16mo ago
the app closes when I put continue
monkeyoohlala
monkeyoohlala16mo ago
monkeyoohlala
monkeyoohlala16mo ago
what are these errors? the top error I know the other errors
phaseshift
phaseshift16mo ago
Style rule messages. Not errors
monkeyoohlala
monkeyoohlala16mo ago
what is top one
phaseshift
phaseshift16mo ago
Self explanatory
monkeyoohlala
monkeyoohlala16mo ago
I take out the string[] args?
phaseshift
phaseshift16mo ago
Yeah, that's what it's saying
monkeyoohlala
monkeyoohlala16mo ago
should I be using switch instead of loop and if statements?
phaseshift
phaseshift16mo ago
Switch doesn't loop If doesn't loop
monkeyoohlala
monkeyoohlala16mo ago
should I be using switch instead of if is what I meant
phaseshift
phaseshift16mo ago
A lot of the time they're interchangeable
Accord
Accord16mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
❔ My project runs successfully but doesn't load ( works fine when I run it without debugging )my project was working fine but suddenly whenever I run it it keeps loading without showing anythingOnly assignment, call, increment, decrement, await, and new object expressions can be used as a statim a noob and why cant i make my console make a beep sound? I didnt understand the error msg❔ multiple Async responsesSo im trying to use async for the first time, i am making a few api requests one after the other, thInvoke Event on boolean set in systemclassI have my own TcpClient class that inherits TcpClient and I wanna invoke an event when one of the bo❔ How to properly handle exceptions between API controller and service layer?I'm creating an API and I'm having trouble figuring out how to properly catch errors between my serv❔ Question regarding Pipe[Reader/Writer].Complete(Exception) (System.IO.Pipelines)If you put in an exception, where does it come back out exactly? Where does the exception get handle❔ How would I call a method created as a top level statement outside of the initial file?I have Program.cs with a method that is a static int, ```static int Example()``` and have tried to c❔ Visual Studio Build doesn't run on other computerSo I made a Visual Studio program for a client that has a bunch of dll when built, however, when i s❔ ASP.net Web shop , cart . customersI am developing shop ASP.net CORE but i am not sure how to make the buttons and "cart " , and cuhow to get clicked button of context menu stripBasically the title. The screenshot is as far as i got