Reputation: 11
Can someone tell me why this loop is continuous?
while(sum !=7 || sum!=pt){
System.out.println(sum);
die1.roll();
die2.roll();
sum = (die1.getNumber() + die2.getNumber());
JOptionPane.showMessageDialog(null, "The sum of your numbers are "+sum);
}
Even if the sum is equal to 7 or the variable pt then the loop keep on going for some reason.
Upvotes: 1
Views: 56
Reputation: 930
Change ||
to &&
. Your loop will continue while one of the conditions evaluates to true. In order to make it stop when one becomes true, you need to change your boolean operator.
Upvotes: 1