---
title: "forEachChange"
description: "Iterates over all the changes in this [ChangeList].

Changes are iterated by index, so any changes made by [block] after the current one will be
visited by [block]. [block] should not make any new changes _before_ the current one or changes
will be visited more than once. If you need to make changes, consider using
[forEachChangeReversed]."
type: "function"
---

<div class='type'>Function</div>


<a id='references'></a>
<div class='sourceset sourceset-common'>Common</div>


```kotlin
@ExperimentalFoundationApi
inline fun ChangeList.forEachChange(block: (range: TextRange, originalRange: TextRange) -> Unit)
```


Iterates over all the changes in this `ChangeList`.

Changes are iterated by index, so any changes made by `block` after the current one will be
visited by `block`. `block` should not make any new changes _before_ the current one or changes
will be visited more than once. If you need to make changes, consider using
`forEachChangeReversed`.



## Code Examples
### BasicTextFieldChangeIterationSample
```kotlin
@Composable
fun BasicTextFieldChangeIterationSample() {
    // Print a log message every time the text is changed.
    BasicTextField(
        state = rememberTextFieldState(),
        inputTransformation = {
            changes.forEachChange { sourceRange, replacedLength ->
                val newString = asCharSequence().substring(sourceRange)
                println("""$replacedLength characters were replaced with "$newString"""")
            }
        },
    )
}
```

