Examples of Objective-C Loops


/ Published in: Objective C
Save to your folder(s)



Copy this code and paste it in your HTML
  1. //Loops
  2.  
  3. //For loop
  4.      for (int y = 0; y < 3; y ) {
  5.      NSLog(@\"y = %i\", y);
  6. }
  7.  
  8. //Do loop
  9. x = 0;
  10. do{
  11.      NSLog(@\"x = %i\", x);
  12.      x ;
  13. }
  14. while(x <= 4);
  15.  
  16. //While loop
  17. x = 0;
  18. while (x <= 4 ) {
  19.      NSLog(@\"x = %i\", x);
  20.      x ;
  21. }
  22.  
  23. //For each loop
  24. //Create an array and add elements to it
  25. NSMutableArray *anArray = [[NSMutableArray alloc] init];
  26. [anArray addObject:@\"Element 1\"];
  27. [anArray addObject:@\"Element 2\"];
  28. [anArray addObject:@\"Element 3\"];
  29.  
  30. //Use a for each loop to iterate through the array
  31. for (NSString *s in anArray) {
  32.      NSLog(s);
  33. }
  34. //Release the array
  35. [anArray release];

URL: http://howtomakeiphoneapps.com/2009/04/examples-of-objective-c-loops-2/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.