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?