Michael Rippee wrote:
Well, that's not a valid expression. What are you trying to achieve there?
(You really shouldn't be using == or != for comparing strings: you should be using the equals() method. But that's not what's stopping it from compiling).
Michael Rippee wrote:Awesome, thank you. I'll code that in real quick and mark this post resolved if it solves the problem. Of course, I'm still curious why it wouldn't even compile. What I wrote seems like it would be an expression, even if it wouldn't 'work'.
What you wrote ...
is not valid Java. And hence, doesn't compile. Java follows very specific rules that is specified by the JLS -- it is probably better to learn those rules, than to determine it via "seems like" it should work.
This is logically equivalent to what you seem to be getting at. That is, if reply doesn't equal "Yes", code is not going to loop, period. What you wrote is invalid syntax if you meant to stipulate two (unnecessary) conditions for "reply". As was previously suggested, use "equals" for string comparison. With objects in general, "==" only checks for same reference (memory address)..