i = arr[0] <- 1 arr[1] = 0; i = arr[1] <- 0 (it's been updated above) arr[0] = 0; i = arr[2] <- 3 arr[3] = 0; i = arr[3] <- 0 (it's been updated above) arr[0] = 0;
Result:0,0,3,0
Your for-loop is different. You are incrementing i from 0 to the length of the array. The enhanced for loop sets i to the value of each element of the array. It should look like