do{
Scanner scan = new Scanner(System.in);
String value = scan.nextLine();
}while(!value.equals("example")/* need another condition here*/);
我想在这里放两个(或更多)条件,其中任何一个都应该是真的停止循环。谢谢你的帮助。
答案 0 :(得分:3)
布尔运算符
AND (&&
)
p q p && q
T T T
T F F
F T F
F F F
或(||
)
p q p || q
T T T
T F T
F T T
F F F
所以,要在你的条件下使用它。
if (x != 9 && x != 10) { ... }
if (x == 0 || x == 5) { ... }
答案 1 :(得分:2)
您是否尝试过使用&&或||条件之间?我是新人,我希望我不会说明显的。
... while(!value.equals(“example”)&& otherCondition ||!found)...
答案 2 :(得分:0)
condtion s:cond1,cond2,cond3,.... condN。
“其中任何一个都应该是真的”=(cond1 == true&& cond2 == true&& cond3 == true&& ... condN == true)
我的代码就像: 停止循环=!在所有表达之前
做{
} while(!(cond1 == true&& cond2 == true&& cond3 == true&& ... condN == true));
答案 3 :(得分:0)
因此,如果你想要停止循环wenn其中一个语句为真或两者都为真,你需要使用布尔值或运算符" ||"。
如果两个陈述都应该为真,那么你需要使用boolena和operator"&&"