posted 21 years ago
In your first example keep in mind that the increment part of the for loop is executed at the end of the loop.
When the first println is reached i is still 0, then at the end of the for loop, right after the println, the value of nArray is set to 1 then it loops again. Now i is 1 and the value of nArray is still 0 (the default), and so on. You are always printing the value of the element you ahven't reached yet.
In your second example you first loop through and assign all of the array elements a value then you print out the values.
hope that helps
[ March 11, 2002: Message edited by: Dave Vick ]