Arrays and “For” Loops
To assign or use all the elements of an array in order, a “for” loop is handy.
int max = 8;
int numbers [ ] = new int [ max ] ;
for ( int i = 0; i < numbers.length; i++ )
{
numbers [ i ]= i * 2;
}
0 1 2 3 4 5 6 7
0 2 4 6 8 10 12 14
Previous slide
Next slide
Back to first slide
View graphic version