【发布时间】:2017-06-14 01:40:59
【问题描述】:
我很好奇为什么只读取 while 语句中的这些条件之一。我希望 while 语句中的两个条件都为真,以便 while 循环停止。我认为 && 意味着两个条件都必须为 TRUE,但是我的程序只读取 while 语句中首先达到的任何条件,然后在没有满足其他条件的情况下终止。这个while语句我做错了什么?
do
{
if((count%2)==0)
{ // even
charlestonFerry.setCurrentPort(startPort);
charlestonFerry.setDestPort(endPort);
FerryBoat.loadFromPort(homePort);
charlestonFerry.moveToPort(endPort);
}//End if
else
{ // odd
charlestonFerry.setCurrentPort(endPort);
charlestonFerry.setDestPort(startPort);
FerryBoat.loadFromPort(partyPort);
charlestonFerry.moveToPort(endPort);
}//End else
count++;
}while(homePort.getNumWaiting() > 0 && partyPort.getNumWaiting() > 0);
【问题讨论】:
-
@RobbyCornelissen
a和b与x和y有什么关系 -
&&就是这样工作的。如果左侧结果为假,则计算机不会费心计算右侧。
标签: java conditional