Reputation: 1
Ive got a while loop that keeps running as long as an if is true at least once per loop but i cant find the reason why the loop wont stop. (there are a couple more ifs but i removed them because they are the exact same)
boolean changed = true;
do{
boolean stopLoop = false;
if(remove1=="")
{
EquipmentSlot1.setText(EquipmentSlot2.getText());
EquipmentSlot2.setText("");
stopLoop = true;
}
if(remove2=="")
{
EquipmentSlot2.setText(EquipmentSlot3.getText());
EquipmentSlot3.setText("");
stopLoop = true;
}
if(remove3=="")
{
EquipmentSlot3.setText(EquipmentSlot4.getText());
EquipmentSlot4.setText("");
stopLoop = true;
}
if(stopLoop = false)
{
changed = false;
}
}while(changed);
Upvotes: 0
Views: 286
Reputation: 755
First, your last if is an assignment, not a test of equality, i.e. stopLoop = false should be == false
Second, changed has no way to be false in any if you have shown.
Upvotes: 0
Reputation: 34166
Change
if (stopLoop = false)
to
if (stopLoop == false)
Note that =
is for assignment, ==
for comparison.
Or better yet (and recommended):
if (!stop)
Edit:
Also, to compare String
s, use equals()
method:
if (remove1.equals(""))
...
Upvotes: 2