December 2013
Intermediate to advanced
132 pages
1h 58m
English
CHAPTER 13
![]()
For-Each Loops
For-Each Loops Defined
For-each loops are a more specific type of loop that can only be used with collection objects like NSArray and NSDictionary. You can use a for loop when you want to move through a list of objects to perform an action on each object in the list.
For example, let’s take the array example from Chapter 8.
NSArray *numbers = @[@-2, @-1, @0, @1, @2];
In Chapter 8, you used the enumeration method with a block to go through the list and square each number. You can use a for loop as an alternative to the enumeration method.
for (NSNumber *num in numbers){ NSLog(@"num ^ 2= %f", [num floatValue] * [num ...
Read now
Unlock full access