r=r+1
is an Assignment statement, this means it reallocates r
, so it no longer refers to its pair in the parent scope. but r[i]=r[i]+1
Mutates r value, mutation is differ from assignment (a good description here), and after that r
still refers to its pair variable in the parent scope.