previous | index | next

Arrays and Iteration

Because arrays have homogeneous data and can be large, they are normally processed iteratively.

Array indexes are well suited to serve as values of loop control variables.

Array sizes are well suited to serve as boundary conditions:

  const int SIZE = 10;
  int v[SIZE];
    
  for (int i = 0; i < SIZE; i++) {
    ... process the element v[i] ...
  }

It's good practice to give constant names to array sizes.


previous | index | next