[英]checking two conditions simultaneously in a do-while loop
在tic-tac脚趾代码中,我有一个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)));
在你写作时:
!win(x)||!loose(x)
你说没赢或不输,循环将在第一次结束时终止。 您可以使用以下内容:
do{
//still the same checking
} while (!win(x)&&!loose(x));
要么
do{
//still the same checking
} while (!(win(x)||loose(x)));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.