When programming with loops, you often must pass data from the current iteration to the next iteration. Shift registers are a great tool for these types of tasks.
For example, the code below uses a shift register to gradually change the servo’s position in each iteration of the while loop. It gets incremented by steps of 0.01 up to value 1, then it resets to 0.
The code first initializes the left shift register with a value of 0, which will be used for the first iteration of the while loop. It then propagates through the code, which yields the result 0.01. This is then pushed to the shift register on the right. The shift register takes this number and brings it around to the register on the left; look at the black arrows for better visualization. The left shift register takes this new value and passes it back into the while loop code. For example, in the second iteration of the while loop the left shift register will have a value of 0.01. Notice that constant 0 is ignored at second iteration and any future iterations. Once again, this is an initialization constant; thus, it is used only in the first loop.
To include shift registers in your code, right click the tunnel you would like to pass data to future iterations on the loop you are using and select Replace with Shift Register.
Further explanation of shift registers can be found in the links below: