Table Of Contents

Accessing Data from the Previous Loop Iteration

Last Modified: January 12, 2018

After a loop completes a single iteration, sometimes you want to use the value of one of its calculations in the next loop iteration. You can use a shift register to pass data from the most recent iteration to the next iteration.

What to Use

What to Do

Create the following diagram to pass data from the most recent loop iteration to the next iteration.

Customize the gray sections for your unique programming goals.

To share data with the next loop iteration, pass the data into a shift register on the right border of the loop. This right shift register passes that data to a corresponding left shift register.

To create a pair of shift registers, right-click the loop border and select Create Shift Register.

The left shift register contains data passed from the right shift register. Access this data by wiring the output of the left shift register to the code inside the loop.

For the first loop iteration, an initialized shift register returns the value wired to its input.

If you do not initialize the shift register, it shares the data it held the last time the loop executed, even if that data is from a previous execution of the VI containing the loop.

After the loop executes, access the data from the last iteration by wiring the output of the right shift register to the rest of the program.

Only values from the last iteration exit the loop through the output of the right shift register.


In the previous example, the value the left shift register passes into the loop changes after each iteration. The following table records the data each shift register contains after each loop iteration if the initial value wired to the left shift register is 10 and the loop count is 3.

Shift Register Value after First Iteration Value after Second Iteration Value after Third Iteration
Left shift register 10 15 20
Right shift register 15 20 25

Recently Viewed Topics