1

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.

1
  • Change '||' to '&&'. Commented Mar 28, 2015 at 19:58

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.