我通常做Java编程,但想用C#测试我的运气,看看它是什么样的.我更像是一个新手程序员,所以也许这很愚蠢,但是在我的Do-While循环中,为什么它只有在我使用&&而不是||时才有效 当试图终止我的循环?对我来说,在Java中,|| 将被使用,因为你想要一个大写或小写"q"来终止.我正在读取终止为"Q"和"q".显然情况并非如此,因为循环终止就好了.我只是不明白这是如何工作的.
namespace Testing_Grounds
{
class Program
{
static void Main(string[] args)
{
string entry;
do
{
Console.WriteLine("This is an inventory screen");
Console.WriteLine("1. Health Potions");
Console.WriteLine("2. Mana Potions");
Console.WriteLine("3. Revive Potions");
Console.Write("Please enter the number of the item " +
"you would like to inspect, or enter \"Q\" to quit: ");
entry = Console.ReadLine();
if (entry.Equals("1"))
{
Console.WriteLine("Health Potions");
}
else if (entry.Equals("2"))
{
Console.WriteLine("Mana Potions");
}
} while (entry != "Q" && entry != "q");
}
}
}
Run Code Online (Sandbox Code Playgroud)