Welcome to the Ranch
Please avoid
...while (true); that denotes an infinite loop, and, to me, an infinite loop is the epitome of a program gone wrong. If you want a
do loop, write it like this:-
No need for
break; any more. Note how you can break the line so it doesn't go over the right margin of the paper or screen.
The link you were given isn't clearly written, but it gives the correct answer, as NM told you. You can rely on
== always returning
false in this program. One of our people, Winston Gutkowski, wrote an
FAQ about it. I like to call
== the, “same object operator,” even if that isn't its official name.
If you try something cimilar in C#, you will find that == gives different results.
Don't declare the
String so early; it Java® it is best to declare local variables as late as possible:-
Improved version:-
Probably better still, using
var:-