Я новичок в C# и кодировании в целом, поэтому, пожалуйста, простите меня. Я хочу использовать цикл while
по умолчанию моего оператора switch
, но я не знаю, как настроить bool для while
. Моя цель состоит в том, чтобы иметь петлю меню до тех пор, пока не будет нажата ни 1, ни 2.Использование цикла while в статусе переключения
switch (userChoice1)
{
case "1":
msg = "\n\nYou have chosen the House Salad with Ranch Dressing. \nPress enter to continue.";
saladChoice = "House Salad with Ranch Dressing";
break;
case "2":
msg = "\n\nYou have chosen the Caesar Salad. \nPress enter to continue. ";
saladChoice = "Caesar Salad";
break;
default:
msg = "\n\nYou have chosen an invalid option. You should have selected \n1 for the House Salad \nor \n2 for the Caesar Salad. ";
Console.Beep();
while (true) // I don't know if the switch should be in the while loop or here
{
}
break;
}
в то время как цикл должен быть вне переключатель – Jake
возможного дубликата [перерыв из цикла в то время, которое содержит переключатель заявление] (http://stackoverflow.com/questions/1987379/break-out-of-a -while-loop-that-contains-a-switch-statement) – Jake