有人可以找到爲什麼這個循環不工作?我是C#的新手。while循環不工作?
while (move == "r" || move == "s" || move == "f")
{
Console.Write("\nEnter your move: ");
move = Console.ReadLine();
switch (move)
{
case "r":
Console.Write("\nYou have reloaded, press enter for Genius");
Console.ReadLine();
break;
case "s":
Console.Write("\nYou have shielded, press enter for Genius");
Console.ReadLine();
break;
case "f":
Console.Write("\nYou have fired, press enter for Genius");
Console.ReadLine();
break;
default:
Console.Write("\nInvalid move, try again\n\n");
break;
}
}
「不工作」的含義是什麼?它不在循環中?它不停止?它過早退出?您是否嘗試過調試並瞭解移動的實際價值? –
它不循環,但Rasel的答案工作得很好 –