Using feedback in iteration
In ModelBuilder, the output of a process can be used as an input to a previous process. This is known as feedback, since an output is fed back to a previous process as input.
There are two ways to set the feedback loop:
- From the variable properties
- Using the connect tool
In the example model below, the output of Buffer is fed back as the input to Buffer in each iteration of the model.
From the variable properties
- Select and right-click the input variable.
On the General tab, select the variable that you want to use as feedback from the Feedback Variable drop-down list.
This will create a dotted blue feedback connector line from the output variable to the input variable. Every time the tool iterates, the output variable will be used as input for the next iteration.
Using the connect tool
- In ModelBuilder, click the Connect tool .
Click the output you want to use as feedback and click the input.
The model knows the output is being connected to the input and automatically creates a dotted blue feedback connector line. Every time the tool iterates, the output variable will be used as input for the next iteration.
Limiting model iteration count
The model must have an iteration count set; otherwise the model will enter a never-ending feedback loop. See the example below.
- To limit the model's iterations, use the For iterator.
- To run the feedback loop for a number of times, enter an appropriate From Value, To Value, and By Value. For example, to iterate the model four times, set a starting From Value of 1, an ending To Value of 4, and an interval By Value of 1.
- Make the output of the For tool a precondition to the next tool. This ensures that the iteration number is available before the next tool executes. Learn more about setting up a precondition
- To avoid overwriting the output of each iteration, append the output name with the %Value% inline variable. When the model runs, %Value% will be replaced by number 1, 2, 3, 4 coming from the output parameter Value of the For iterator.
- Connect the output of the tool as a feedback to the input, as in the example below where the output of Buffer is connected to the Input variable as feedback.
- Also, connect the output of the tool (Output in the example) to the Collect Values tool.
- Run the model.