Results 1 to 3 of 3
  1. #1
    diamonddragon is offline Senior Member
    Join Date
    Jan 2012
    Posts
    210
    Rep Power
    3

    Default Empty while loop

    Is ok to use an empty while loop?

    Say:
    Java Code:
            do {                 
                char[][] word = generateWord(words);
                while (guess(word)) {                                               
                }
                System.out.println("You missed " + missedCount + " time");
            }
            while (playAgain());
        }

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

    Default Re: Empty while loop

    Is ok to use an empty while loop?
    Yes. In general {} is a perfectly well defined block.

    It is another question whether you want to do this. In your example you won't get past the empty block until guess(word) returns false. Is this what you want to happen?

  3. #3
    diamonddragon is offline Senior Member
    Join Date
    Jan 2012
    Posts
    210
    Rep Power
    3

    Default Re: Empty while loop

    Yes, and guess(word) actually returns false in case word is guessed.
    In all other cases, which means, letter is already in the word, letter is not in the word, and word is not guessed, guess(word) returnes true.

Similar Threads

  1. Entering in the loop,even if the value is null or empty
    By swati.jyoti in forum New To Java
    Replies: 9
    Last Post: 09-08-2010, 06:10 PM
  2. Empty Form?
    By Vorfin in forum New To Java
    Replies: 13
    Last Post: 07-05-2010, 12:54 AM
  3. Empty FileInputStream..
    By dudejonne in forum New To Java
    Replies: 5
    Last Post: 11-08-2009, 09:21 PM
  4. Why is this stakc empty?
    By jigglywiggly in forum New To Java
    Replies: 1
    Last Post: 10-09-2009, 07:22 AM
  5. empty arrays.
    By circuspeanuts in forum New To Java
    Replies: 11
    Last Post: 04-06-2009, 08:08 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
  •