<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/ops/core.py#L719-L745) |

For loop implementation.

    tf.keras.ops.fori_loop(
        lower, upper, body_fun, init_val
    )

<br />

<br />

<br />

| ## Args ||
|---|---|
| `lower` | The initial value of the loop variable. |
| `upper` | The upper bound of the loop variable. |
| `body_fun` | A callable that represents the loop body. Must take two arguments: the loop variable and the loop state. The loop state should be updated and returned by this function. |
| `init_val` | The initial value of the loop state. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| The final state after the loop. ||

<br />

#### Example:

    lower = 0
    upper = 10
    body_fun = lambda i, s: (i + 1, s + i)
    init_val = 0
    keras.ops.fori_loop(lower, upper, body_fun, init_val)
    45