# orbit.utils.create_loop_fn

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/models/blob/v2.20.0/orbit/utils/loop_fns.py#L27-L89) |

Creates a loop function driven by a Python `while` loop.

    orbit.utils.create_loop_fn(
        step_fn
    )

<br />

<br />

<br />

| ## Args ||
|---|---|
| `step_fn` | A function taking a nested structure of [`tf.data.Iterator`](https://www.tensorflow.org/api_docs/python/tf/data/Iterator) or `DistributedIterator`. There are no constraints on the return value of the function (except that it must be compatible with any `reduce_fn` provided to the returned `loop_fn`). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A loop function taking required `iterator` and `num_steps` parameters, as well as optional `state` and `reduce_fn` parameters for accumulating state over multiple iterations of the loop. See the `loop_fn` definition below for additional details. ||

<br />