What is an iterator? [duplicate]

0

In PHP, when I need a given class to have certain behavior in the foreach call, I implement an interface called Generator .

In Python there also seems to be __iter__ , which changes the behavior of the object relative to for .

I've also heard in many other languages ( Java , a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Iteratores_e_geradores"> Javascript and the like) the use of the term Iterator , operations. And I see that this is usually an OOP implementation.

  • After all, what is an Iterator or Iterator?

  • An iterator will always relate to for , foreach , while , and the like?

asked by anonymous 21.06.2017 / 18:52

0 answers