Results 1 to 4 of 4
  1. #1
    Aldius is offline Member
    Join Date
    Oct 2009
    Posts
    7
    Rep Power
    0

    Default exiting a while loop with a string

    Hello all...I seem to be having some trouble exiting a while loop with a string. This feels really embarrassing but here is my code:

    private static String strDifficulty()
    {
    String strDif;

    strDif = JOptionPane.showInputDialog("What difficulty setting would you like? Hard or easy?");

    while (!strDif.equalsIgnoreCase("easy") || !strDif.equalsIgnoreCase("hard"));
    {
    strDif = JOptionPane.showInputDialog("Please enter in either 'hard' or 'easy'. Thank you.");
    }
    return strDif;
    }
    }

    unfortunately I'm stuck in a while loop. any help would be greatly appreciated! Thanks all :).

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Pick a number between 1 and 1000 (but don't say what it is).

    The number you picked was either not equal to 42 or it was not equal to 666.

    Perhaps you don't really mean "!equals()||!equals()" in the condition of your while loop.

  3. #3
    Aldius is offline Member
    Join Date
    Oct 2009
    Posts
    7
    Rep Power
    0

    Default

    lol, thanks. I think i should take a logic course.

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    You're welcome. It's usually enough to say these things out loud to pick up what the problem is. But if you do want the formal treatment of how not "distributes" over and and or, check out De Morgan's laws.

Similar Threads

  1. Exiting on menuSelected action
    By benra in forum New To Java
    Replies: 8
    Last Post: 10-13-2009, 04:58 PM
  2. String and while loop
    By Exception in forum Java Applets
    Replies: 5
    Last Post: 09-24-2009, 12:32 PM
  3. Using string to terminate loop
    By mrblippy in forum New To Java
    Replies: 3
    Last Post: 04-23-2009, 06:16 AM
  4. Entering string in a loop with method
    By Konex in forum New To Java
    Replies: 3
    Last Post: 03-01-2009, 07:33 AM
  5. terminating a while loop with a string
    By tkdvipers in forum New To Java
    Replies: 3
    Last Post: 07-09-2007, 11:23 PM

Posting Permissions

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