Results 1 to 4 of 4
Thread: Problem with while looping
- 02-11-2012, 08:49 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 3
- Rep Power
- 0
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.
Java 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);
- 02-11-2012, 09:02 PM #2
Senior Member
- Join Date
- Feb 2011
- Location
- Georgia, USA
- Posts
- 122
- Rep Power
- 0
Re: Problem with while looping
while(p == true);
comparison vs. assignment. while(p= true) will always return true which is an infinite loop.
- 02-11-2012, 09:02 PM #3
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Re: Problem with while looping
p = true = assignment
p == true or simply while(p) = comparison
- 02-11-2012, 09:05 PM #4
Member
- Join Date
- Feb 2012
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Problem with Looping input dialog
By kiraichi in forum New To JavaReplies: 3Last Post: 02-11-2012, 09:14 PM -
Problem with looping
By jarredh4 in forum New To JavaReplies: 2Last Post: 02-16-2011, 04:56 AM -
Lottery help, looping problem
By hadoken5 in forum New To JavaReplies: 2Last Post: 10-31-2010, 06:48 PM -
Problem With Looping [JAVA]
By jude113 in forum New To JavaReplies: 2Last Post: 03-06-2009, 01:00 PM -
Looping problem
By Tanilo in forum New To JavaReplies: 1Last Post: 08-01-2008, 06:34 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks