Problem with while looping
So, I've been writing basic Java for a while now, almost a year, slowly learning as I go along. My most recent project has been to start writing a text based Pokemon game, and surprisingly; I have not been able to get the second loop, getting the user to input their starter pokemon's name is not working. I have tried for hours trying to get it to work, using do while and string input, a while and integer input, and this is my final try. I was just wondering if someone could point out why this seems to be not working even when the boolean value is declared false after the user chooses (On the final try, an integer) the Pokemon. If you need anymore information on the program I can post it. Please, if you can help.
Code:
boolean p = true;
do {
System.out.println("");
Scanner pokemonkeyboardInput = new Scanner(System.in);
int PS = pokemonkeyboardInput.nextInt();
System.out.println("");
if (PS == 1) {
System.out.println("[Proffesor Oliver] Good choice; a fire type!");
p=false;
} else if (PS == 2) {
System.out.println("[Proffesor Oliver] Grand! The water type!");
p=false;
} else if (PS == 3) {
System.out.println("[Professor Oliver] Good... A fire type!");
p=false;
} else if (PS == 4) {
System.out.println("[Professor Oliver] Ah, Rosalie; such a cute pokemon; and a grass type at that!");
p=false;
} else {
p=true;
System.out.println("[Alexander] It may work if you spell it right...");
p=true;
}
} while (p = true);
Re: Problem with while looping
while(p == true);
comparison vs. assignment. while(p= true) will always return true which is an infinite loop.
Re: Problem with while looping
p = true = assignment
p == true or simply while(p) = comparison
Re: Problem with while looping
Thanks! That worked. I'll be sure to come back here with anymore Java questions, thanks a lot for the help.
Edit: And, silly mistake on my part :P