This is quite easy to understand:
For-each loop has internal counter that moves pointer to next element in each iteration.
So:
1st iteration here is how array looks:
So code
assigns value of 1 to i because pointer points to that value in arr.
That said code looks like this:
and changes arr to look like this:
2nd iteration:
Pointer moves to the next value:
So code
assigns value of 0 to i because pointer points to that value in arr.
That said code looks like this:
and changes arr to look like this:
3rd iteration:
Pointer moves to the next value:
So code
assigns value of 3 to i because pointer points to that value in arr.
That said code looks like this:
and changes arr to look like this:
4th iteration:
Pointer moves to the next value:
So code
assigns value of 0 to i because pointer points to that value in arr.
That said code looks like this:
arr[0] is changed but to the same value and looks like this:
I hope this helps