Java 执行While循环代码
我对这段代码中发生的事情感到非常困惑 我正在做一个do循环,并要求仅在满足两个条件时循环。但当我将赌注设置为0时,循环将继续 我遗漏了什么吗?好吧,如果下注为0,你永远不会指定pot=game1。returnPotAmount;,所以,如果这是它的初始值,pot可能会保持为0,这意味着循环不会终止Java 执行While循环代码,java,loops,while-loop,Java,Loops,While Loop,我对这段代码中发生的事情感到非常困惑 我正在做一个do循环,并要求仅在满足两个条件时循环。但当我将赌注设置为0时,循环将继续 我遗漏了什么吗?好吧,如果下注为0,你永远不会指定pot=game1。returnPotAmount;,所以,如果这是它的初始值,pot可能会保持为0,这意味着循环不会终止 也许你想让你的身体状况变糟0&&bet!=0; 这是您的循环终止代码: do{ game1.getBetAmountFromUser(); bet =
也许你想让你的身体状况变糟0&&bet!=0; 这是您的循环终止代码:
do{
game1.getBetAmountFromUser();
bet = game1.returnBetAmount();
if (bet!=0){
game1.playGame();
pot = game1.returnPotAmount();
System.out.println("");
}
else{
System.out.println("You end the game with pot of $" + formatter.format(pot));
bet = game1.returnBetAmount();
}
}while (pot != 0 && bet == 0);
这意味着,当赌注不为零且赌注为零时,继续前进。但是,当赌注为零时,您希望终止,而不是继续。所以你的代码应该测试赌注不是零。。。继续前进
关键词while与英语中的while意思大致相同。我是个白痴。这就是我在凌晨4点进行编码的结果。我需要一个whilepot=0&&bet!=0
... } while (pot != 0 && bet == 0);