tf.keras.ops.fori_loop

For loop implementation.

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.

The final state after the loop.

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