What is an iterator?

Asked

Viewed 181 times

0

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

In Python seems to exist as well __iter__, that changes the behavior of the object in relation to the for.

I have also heard in several other languages (Java, Javascript and related) the use of the term Iterator, in similar operations. And I see that this is usually an OOP implementation.

  • After all, what is an Iterator or Iterator?

  • The use of the term iterator or iterator is directly related to object orientation?

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

  • If not, edit to make it clearer what these do not answer.

  • Related: https://answall.com/q/191582/101

  • Maybe dup also: https://answall.com/q/185497/101

  • @mustache, hang on, leave as reference :p

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.