Should I do loops in reverse order ?
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