Iteration, often referred to as looping, means to repeat a process over and over with some degree of automation. Iteration is very important because automating repetitive tasks reduces the time and effort required to perform the tasks. With iteration in ModelBuilder, a process can be executed over and over using different settings or data in each iteration. ModelBuilder also provides flexibility in iteration, as an entire model or simply a single tool or process can be executed repeatedly.
Iterates over a starting and ending value by a given value. It works exactly like For in any scripting/programming language, executing through a set number of items.
Works exactly like 'while' in any scripting/programming language, executing "while" a condition is true or false for the input or set of inputs.
Iterates over features in a feature class.
Iterates over rows in a table.
Iterates over each value in a field.
Iterates over a list of values.
Iterates over datasets in a Workspace or Feature Dataset.
Iterates over feature classes in a Workspace or Feature Dataset.
Iterates over files in a folder.
Iterates over rasters in a Workspace or a Raster Catalog.
Iterates over tables in a workspace.
Iterates over workspaces in a folder.
Understanding an iterator
Each iterator has a set of parameters that may differ from the other iterators, but the overall structure of all iterator tools is very similar. A commonly used iterator, Iterate Feature Classes, is explained below.
Iterate Feature Classes requires an Input Workspace where all the feature classes to iterate through are stored. Two additional parameters, Wildcard and Feature Type, are used to restrict what feature classes in the workspace are iterated:
- Wildcard limits the feature classes by their names.
- Feature Type limits the feature classes by their feature types: annotation, arc, dimension, edge, junction, label, line, node, point, polygon, region, route, or TIC.
The Recursive parameter is used to control the iteration over feature classes within subfolders in the workspace.
Iterate Feature Classes has two output variables: the output feature class and the name of the feature class. The output feature class can be connected to the next tool for processing, and the Name variable can be used for inline variable substitution. For example, if the Buffer tool was added to the model, and the Feature Class variable was connected to the tool, every feature class in the workspace would be buffered.
Iterator input and output
Below is a list of iterators and what their input and outputs are. A number of iterators have a Value or Name as second output, which can be used for inline variable substitution.
|Iterator||Input||Output 1||Output 2|
Boolean—True or False Value
Workspace or Feature Dataset
Workspace or Feature Dataset
Workspace or Raster Catalog