+ 1

Looping the whole program from the star in c#

how can i loop my program for example if i press y it loop again from the top of my code and if i choose n it will exit my whole program

10th Aug 2018, 6:30 PM
William Changco
William Changco - avatar
2 Respostas
+ 1
Use loops. ;) Just create an infinite loop with something like while(true){}. We'll use this loop to keep the prompts going until the user decides to exit. Inside of the loop, toward the top, have it check user input (ReadLine()) to see if they typed in 'n' or 'exit' or 'whateveryouwant'. If they did, break the loop. If they didn't, proceed. If the loop is broke, then it'll move on and end the program if prompted. Typically, I'd recommend sending them an exit message and then use Console.ReadKey() to get the whole "Press any key to exit..." type of thing if you're using console app. Going strictly by what you said, you'll have an infinite loop as your main outer loop and then at the inner bottom of that loop, you'll have another loop which checks for 'y' or 'n'. If it's 'y' then use 'continue;' and if it's 'n' then use 'break;'. DISCLAIMER: This isn't going to work in SoloLearn Code Playground. It isn't designed to work that way, so you'll want to use a real compiler on your local machine to truly test and practice certain concepts.
10th Aug 2018, 7:05 PM
Fata1 Err0r
Fata1 Err0r - avatar
0
thank you for your help!!
11th Aug 2018, 7:08 AM
William Changco
William Changco - avatar