Results 1 to 2 of 2
  1. #1
    awesom is offline Member
    Join Date
    Oct 2011
    Posts
    16
    Rep Power
    0

    Default Converting a for loop to a do-while loop

    Hi,

    I got a question, i want to convert my for-loop, to a do-while loop.

    The for loop is like this:
    Java Code:
    public void listNotes()
        {
            for(String note : notes) {
                System.out.println(note);
            }
        }
    How can i convert this to a do-while loop?

    Greets,

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,814
    Rep Power
    25

    Default Re: Converting a for loop to a do-while loop

    Rewrite the for loop to use indexes instead of iterators.
    Then look at the loop control logic, see how the index variable is used and rewrite the logic for the do{} while loop using that same type of logic with an index.

    Can you get an iterator for notes? Then your logic could use an iterator instead of an index.

Similar Threads

  1. Replies: 2
    Last Post: 11-07-2011, 03:25 AM
  2. Replies: 1
    Last Post: 10-01-2011, 03:12 AM
  3. JTextField loop 2x for-loop WEIRD!
    By Streetproject in forum AWT / Swing
    Replies: 2
    Last Post: 02-16-2011, 06:46 PM
  4. Convert do while loop to for loop
    By sandeeptheviper in forum New To Java
    Replies: 3
    Last Post: 01-03-2011, 01:37 PM
  5. while-loop stopping on first loop
    By davester in forum New To Java
    Replies: 6
    Last Post: 06-26-2009, 09:46 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
  •