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

    Default Converting a for loop to a do-while loop


    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) {
    How can i convert this to a do-while loop?


  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

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