While循环与一起使用但不是&&,不明白为什么?

c#

该程序的目标是掷两个骰子,直到它们都等于 6。当我在 while 语句中使用 && 时,它在一个骰子等于 6 后停止。这是为什么呢?不应该&& 测试第一个条件,然后测试第二个条件是否正确?

while ((diceOne != 6) || (diceTwo != 6)) {
    diceOne = numberGeneration.Next(1, 7);
    diceTwo = numberGeneration.Next(1, 7);
    attempt = ++attempt;

    Console.WriteLine("Your first dice is: " + diceOne + " your second dice is: " + diceTwo);
    Console.WriteLine("Press any button to continue");
    Console.ReadKey();

}

Console.WriteLine("It took you " + attempt);
Console.WriteLine("Press any key to continue");
Console.ReadKey();

回答

它停止是因为你打破了一个骰子不同于 6 的条件。

while ((diceOne != 6) && (diceTwo != 6))

While 将在两个条件都为真时执行。


以上是While循环与一起使用但不是&&,不明白为什么?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>