#Does anyone know why when I type 'no' the while loop still equals true?

1 messages · Page 1 of 1 (latest)

cursive otter
#

because "no" has a different address, this is not PHP, Perl, Python

#

in C, C++, Java, the above is not true

#

in Java if both string are intern() then it could be true

#
while(play == true) {

for(int i = 0; i < 3; ++i) {

                ++userTurn;

                System.out.println("Would you like to roll?");

                String userInput = scnr.next();

                if ("no".equals(userInput) || (theDice.countNumOnes() == 2)  || theDice.countNumOnes() == 3 || userTurn == 3 ) {

                    play = false;

            }
        }
        }
#

you might as well use "no".equalsIgnoreCase(userInput)

sand bramble
#

thank you \

cursive otter
#

also yoda style to avoid NPE, by putting the constant on the LEFT

sand bramble
#

how do u get ur code in that box

cursive otter
#

triple back tick

#

String.equals() checks for intern() then equality

cursive otter
#

same pointer ? or intern? yes

#

otherwise is it String?