在井字游戏代码中,我有一个 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/