c++ - 在 do-while 循环中同时检查两个条件

标签 c++ do-while

在井字游戏代码中,我有一个 do-while 循环来检查是否有玩家赢了..所以,像这样

do{
//does some player's input and other things..
}while(!win(x));

现在,最大的问题是在这个循环中,它将继续循环直到其中一个玩家获胜。 现在,我如何使用相同的 do-while 循环检查平局?

我可以做这样的事情吗:

do{
 //still the same checking
}while(!win(x)||!loose(x));

我确实试过了,但它只是弄乱了代码。我怎么可能在游戏中查看平局?

谢谢

最佳答案

你的逻辑有点不对 - 改变循环条件:

do{
 //still the same checking
}while(!win(x)||!loose(x));

到:

do{
 //still the same checking
}while(!win(x)&&!loose(x));

或者更容易理解但等效的替代方法:

do{
 //still the same checking
}while(!(win(x)||loose(x)));

关于c++ - 在 do-while 循环中同时检查两个条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12402486/

相关文章:

Java - WHILE 中的 Swing 计时器,带有启用/禁用按钮

公共(public)成员的 C++ 替代方案

c++ - 如何通过获取用户输入来设置类的常量成员值?

debugging - NetLogo:同时/重复海龟运动以下补丁自己的变量

c++ - 任何人都可以解释这个简单逻辑背后的逻辑吗?我迷路了

java - 出现 do-while 错误

Java Do-While 循环 - 如何使用 Q 选项结束程序

c++ - 默认初始化与值初始化

c++ - 使用 GCC 4.2.1 在 C++ 中将 char 输出为十六进制流

c++ - 构造函数 - 关于性能?