January 2014
Intermediate to advanced
736 pages
70h 43m
English
Many common array manipulations use for statements. As an example, the following for statement sets all the elements in row 2 of array a in Fig. E.15 to zero:
for ( int column = 0; column < a[ 2 ].length; column++) a[ 2 ][ column ] = 0;
We specified row 2; therefore, we know that the first index is always 2 (0 is the first row, and 1 is the second row). This for loop varies only the second index (i.e., the column index). If row 2 of array a contains four elements, then the preceding for statement is equivalent to the assignment statements
a[ 2 ][ 0 ] = 0;a[ 2 ][ 1 ] = 0;a[ 2 ][ 2 ] = 0;a[ 2 ][ 3 ] = 0;
Read now
Unlock full access