• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Should I do loops in reverse order ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Should I do loops in reverse order ?


  • Subject: Should I do loops in reverse order ?
  • From: Martin <email@hidden>
  • Date: Mon, 27 Nov 2006 17:59:01 +0100

Hi,

Let's say I'm looping through an array's objects, and, in that particular case, order doesn't matter :

int i;
for ( i=0 ; i<[myArray count] ; i++ ) {
	// do stuff
}

Is it much better and should I always do (as order doesn't matter here) the following thing...

int i;
for ( i=[myArray count]-1 ; i>=0 ; i-- ) {
	// do stuff
}

...in order to call only once [myArray count] instead of calling it at each loop ? Is it much faster ? Is there a difference if myArray is a NSArray or a NSMutableArray (in that case I also need to assume that I don't modify the array's count in "//do stuff").

Thanks,
Martin.




_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Should I do loops in reverse order ?
      • From: "Sean McBride" <email@hidden>
    • Re: Should I do loops in reverse order ?
      • From: Shawn Erickson <email@hidden>
    • Re: Should I do loops in reverse order ?
      • From: John Stiles <email@hidden>
    • Re: Should I do loops in reverse order ?
      • From: "Scott Ellsworth" <email@hidden>
  • Prev by Date: Re: Deployment target set to 10.4, still launches on 10.3.9
  • Next by Date: Re: Debugging complex autorelease/release/retain issue
  • Previous by thread: Re: Smart sort
  • Next by thread: Re: Should I do loops in reverse order ?
  • Index(es):
    • Date
    • Thread