Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Question 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);

  2. #2
    yellowledbet is offline Senior Member
    Join Date
    Feb 2011
    Location
    Georgia, USA
    Posts
    122
    Rep Power
    0

    Default Re: Problem with while looping

    while(p == true);

    comparison vs. assignment. while(p= true) will always return true which is an infinite loop.

  3. #3
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    786
    Rep Power
    5

    Default Re: Problem with while looping

    p = true = assignment
    p == true or simply while(p) = comparison

  4. #4
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default 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
    Last edited by MysteryForumGuy; 02-11-2012 at 09:05 PM. Reason: Added information

Similar Threads

  1. Problem with Looping input dialog
    By kiraichi in forum New To Java
    Replies: 3
    Last Post: 02-11-2012, 09:14 PM
  2. Problem with looping
    By jarredh4 in forum New To Java
    Replies: 2
    Last Post: 02-16-2011, 04:56 AM
  3. Lottery help, looping problem
    By hadoken5 in forum New To Java
    Replies: 2
    Last Post: 10-31-2010, 06:48 PM
  4. Problem With Looping [JAVA]
    By jude113 in forum New To Java
    Replies: 2
    Last Post: 03-06-2009, 01:00 PM
  5. Looping problem
    By Tanilo in forum New To Java
    Replies: 1
    Last Post: 08-01-2008, 06:34 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •