Logo

Programming-Idioms

History of Idiom 7 > diff from v38 to v39

Edit summary for version 39 by :
[C] Comment emphasize

Version 38

2016-02-05, 10:49:14

Version 39

2016-02-05, 10:51:07

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

Code
int i;
for(i=0 ; i<n ; i++){
  T x = items[i];
  printf("Item %d = %s\n", i, toString(x) );
}
Code
int i;
for(i=0 ; i<n ; i++){
  T x = items[i];
  printf("Item %d = %s\n", i, toString(x) );
}
Comments bubble
The loop variable i is the index. Inside the loop, access the value with items[i]
Comments bubble
The loop variable i is the index. Inside the loop, access the value with items[i]