gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 03:31:32 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com