# For-each on Iterator?

**URL:** <https://discuss.kotlinlang.org/t/for-each-on-iterator/6050>\
**Category:** Language Design\
**Created:** [January 2, 2018, 1:45pm UTC](https://discuss.kotlinlang.org/t/for-each-on-iterator/6050 "2018-01-02T13:45:53Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jstuyts](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/jstuyts/32/2141_2.png) [@jstuyts](https://discuss.kotlinlang.org/u/jstuyts)\
**Post date:** [January 2, 2018, 1:57pm UTC](https://discuss.kotlinlang.org/t/for-each-on-iterator/6050/2 "2018-01-02T13:57:45Z")

</div>

There is already an extension function to iterate over the elements of an iterator using [`forEach`](http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/for-each.html).

> [@tango24](#):
>
> Would it be possible (from a language design perspective) to additionally allow looping over objects that are iterators (i.e. have member of extension functions next() and hasNext())?

Assuming you want to use objects that do not implement `Iterator` but do have the methods of `Iterator`, as an iterator, this has been discussed before. The Kotlin team decided not to implement it: ["Extension types" for Kotlin](https://discuss.kotlinlang.org/t/extension-types-for-kotlin/1390). Also see [Implicit interfaces as in Go](https://discuss.kotlinlang.org/t/implicit-interfaces-as-in-go/587) and [Implicit interfaces](https://discuss.kotlinlang.org/t/implicit-interfaces/149).

---

_[View the full topic](https://discuss.kotlinlang.org/t/for-each-on-iterator/6050)._
