简体   繁体   English

while循环中的多个条件(或) - java

[英]multiple conditions (or) in while loop - java

My while loop looks like this currently:我的 while 循环目前看起来像这样:

    while((0 <= trader.getWallet()) || (0 <= days)) {  
// do something
}

so if any of those two conditions are false somewhere in the loop the program will exit, but my program doesn't seem to listen to the second condition only the first, but it would listen to them separately if I just put them in one at a time for testing, so did I write this while loop wrong?所以如果这两个条件中的任何一个在循环中的某处为假,程序将退出,但我的程序似乎并没有只听第二个条件,但如果我只是把它们放在一个测试的时间,所以我写这个while循环错了吗?

In case of Logical OR if any one of the two conditions is true whole statement shall execute to be true.在逻辑或的情况下,如果两个条件中的任何一个为真,则整个语句应执行为真。 In case of Logical AND both the conditions have to be true for the whole statement to be true.在逻辑与的情况下,两个条件都必须为真,整个语句才能为真。 So,you can use logical AND所以,你可以使用逻辑与

while((trader.getWallet>=0()) && (days>=0))

If the first condition is true then OR won't evaluate the second condition,如果第一个条件为真,则 OR 不会评估第二个条件,

Instead, it should be相反,它应该是

while(trader.getWallet() > 0 && days > 0) {  
   // do something
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM