小编Zac*_*ler的帖子

DoWhile循环对我来说很奇怪(对我来说).谁能解释一下?

我通常做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)

c# do-while

2
推荐指数
1
解决办法
109
查看次数

标签 统计

c# ×1

do-while ×1