Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: loop once or loop multiple times

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default loop once or loop multiple times

    To keep this simple, I have a list of items and i have to do two tasks with this list. For efficiency one programmer is saying loop once and perform both tasks. The other programmer is saying make two different methods for each task for readability and maintainability, so you would actually be looping twice through the list. Which is the better practice? Thanks


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,135
    My Mood
    Mellow
    Thanks
    187
    Thanked 659 Times in 646 Posts

    Default Re: loop once or loop multiple times

    Test/quiz question?

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: loop once or loop multiple times

    No, we just did code review at work and this came up. Maybe this should be in the Object Oriented Forum?

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,135
    My Mood
    Mellow
    Thanks
    187
    Thanked 659 Times in 646 Posts

    Default Re: loop once or loop multiple times

    Then go with the more senior/respected programmer's comment. If it were me, and I wrote your company's best practices/style guide, I'd document the second programmer's comments as company policy, but it's not me.

Similar Threads

  1. Loop to find and replace multiple instances of a char
    By Olympaphibian89 in forum Loops & Control Statements
    Replies: 1
    Last Post: October 25th, 2012, 04:11 PM
  2. [SOLVED] Problem with multiple output statements in DO WHILE loop.
    By Nismoz3255 in forum Loops & Control Statements
    Replies: 0
    Last Post: February 22nd, 2012, 08:14 PM
  3. Creating multiple objects with a for loop
    By JackCannon15 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 20th, 2011, 06:26 PM
  4. Creating multiple arraylists with a loop?
    By DLX in forum Collections and Generics
    Replies: 4
    Last Post: December 28th, 2010, 05:58 PM
  5. Replies: 1
    Last Post: October 16th, 2010, 03:32 PM

Tags for this Thread