Logo

Programming-Idioms

History of Idiom 7 > diff from v93 to v94

Edit summary for version 94 by OC:
New Obj-C implementation by user [OC]

Version 93

2020-10-06, 10:34:16

Version 94

2020-10-10, 19:26:48

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Variables
i,x,items
Variables
i,x,items
Extra Keywords
traverse traversal
Extra Keywords
traverse traversal
Imports
@import Foundation;
Code
[items enumerateObjectsUsingBlock:^(id x, NSUInteger i, BOOL *stop) {
  NSLog(@"Item %lu = %@",(u_long)i,x);
}];
Comments bubble
The plain-C approach can be used as well. Showing another, object-oriented possibility. Typecast needed with %lu (same as in printf) for multi-platform compatibility. The stop argument serves same purpose as plain-C break