Re: Arrays & For Loops
Re: Arrays & For Loops
- Subject: Re: Arrays & For Loops
- From: "John C. Randolph" <email@hidden>
- Date: Tue, 1 Apr 2003 14:34:27 -0800
On Tuesday, March 25, 2003, at 06:21 AM, Bill Bumgarner wrote:
Alternatively, just use an enumerator and be done with it:
NSEnumerator *arrayEnumerator = [myArray objectEnumerator];
id anObject;
while(anObject = [arrayEnumerator nextObject]) {
....
}
Let me point out again some of the advantages of enumerators:
1) No fencepost errors. Ever.
2) They maintain their state and you can pass them around, eg:
NSEnumerator *arrayEnumerator = [myArray objectEnumerator];
id anObject;
while(anObject = [arrayEnumerator nextObject]) {
if ([anObject meetsSomeCriterion])
[someoneElse handleTheRestOfThis:arrayEnumerator];
}
-jcr
John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.