Answer the question
In order to leave comments, you need to log in
What are iterators in python, c#, c++, js? How to use them? What are they for? Have you read it and haven't figured out what it's about yet?
0. What are iterators in python, c#, c++, js?
1. How to use them?
2. What are they for?
Did you read until you understood their essence?
Answer the question
In order to leave comments, you need to log in
In a nutshell, an iterator is an object that, each time, upon request, can produce either some element or a message that it has no more elements.
The simplest option is an iterator over a list. Each time, upon request, it will issue one element of the list, starting from the first and ending with the last, after which it will display a message that the elements have ended.
In this case, the iterator does not necessarily issue elements from a pre-existing collection, it can create them right at the time of the request according to a certain rule. Such iterators can also be infinite, that is, no matter how many requests they receive, they are always ready to issue more and will never say that the elements have ended.
An example is an iterator that produces 0 or 1 by alternating between them.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question