-3
switch文を2回だけループすることができました。 2回目の後、スイッチのケースから選択したオプションに関係なく、コンソールが閉じます。ユーザーが停止することを決定するまでスイッチケースをループし続けるように、コードを変更する方法はありますか?ステートメントを2回出力した後にwhileループを続行するにはどうすればよいですか?
ありがとうございます。
int userChoice = 0;
Console.WriteLine("This is an application. It has many different modes.");
Console.WriteLine("You can activate the mode of the application, which can be inserting, retrieving, printing, saving or uploading.");
Console.WriteLine("Type 'I' to insert, 'R' to retrieve, 'P' to print, 'S' to save, 'U' to upload the data, or 'T' to terminate the application.");
string mode = Console.ReadLine();
switch (mode)
{
case "I":
Console.WriteLine("You have chosen to insert the data.");
break;
case "R":
Console.WriteLine("You have chosen to retrieve the data.");
break;
case "P":
Console.WriteLine("You have chosen to print the data.");
break;
case "S":
Console.WriteLine("You have chosen to save the data.");
break;
case "U":
Console.WriteLine("You have chosen to upload the data.");
break;
case "T":
Console.WriteLine("You have chosen to terminate the application.");
return;
}
// Two modes, quit option
if (mode == "I" || mode == "R")
{
Console.WriteLine("The application will stay in the insert or retrieve modes. Press 'Q' to exit to the modes to return to the main menu.");
}
while (userChoice != 0)
{
Console.WriteLine("Please choose one of the modes {0}.", userChoice);
userChoice++;
}
Console.WriteLine("Type 'I' to insert, 'R' to retrieve, 'P' to print, 'S' to save, 'U' to upload the data, or 'T' to terminate the application.");
Console.ReadLine();
*内側*ループ –
があなたのswitch文は、任意のループ –