OK but short answer.
Turn on execution highlighting and watch the code exeute.
Drop some probes on the wires and watch how the data changes in each step.
Shift regitsers store data from one iteration of a loop for the next.
What ever data is wired to the SR's before the loop starts is stuffed in a buffer (SR).
On the first iteraction the data the was put there when loop is started is used.
After that the contents of the SR is changed depending on what is wirede to the "right" SR from inside the loop.
In your example, I keep a "working version" of your data in the SR. I simply decide which part of the data in the SR should be changed and act only on those elements.
Execution Highlighting reveals all!
Watch, learn have fun!
Ben