Cocoa Maker 4 - Loops and Goto

Share:

Listens: 0

Cocoa Maker

Technology


James (MrGeckosMedia.com), joined by, Eduardo (MegaEduX.com), and Karl, teaches how loops, arguments, and goto works in Cocoa.15:35Example code from episode.Loops Example#import int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int i=0; while (i!=2) { NSLog(@"%d", i); i++; } i=0; do { NSLog(@"%d", i); i++; } while (i!=3); NSArray *anArray = [NSArray arrayWithObjects:@"Apples", @"Oranges", @"Grapes", @"Bananas", nil]; for (int d=0; d<[anArray count]; d++) { NSLog(@"%@", [anArray objectAtIndex:d]); } NSString *theObject; for (theObject in anArray) { NSLog(@"For In: %@", theObject); } NSEnumerator *theEnumerator = [anArray objectEnumerator]; while (theObject = [theEnumerator nextObject]) { NSLog(@"Enumerator: %@", theObject); } [pool drain]; return 0;}Goto Example#import void testGoto() { NSString *theString = [NSString new]; if (1==12) { goto Error; } goto Cleanup;Error: NSLog(@"An error occurred"); goto Cleanup;Cleanup: NSLog(@"Releasing the string"); [theString release];}int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; testGoto(); [pool drain]; return 0;}Keynote used in this EpisodeKeynote in PDF Format