D
D
D0ct0r_Murder2018-02-04 17:38:46
Programming languages
D0ct0r_Murder, 2018-02-04 17:38:46

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

2 answer(s)
A
Alexander, 2018-02-04
@D0ct0r_Murder

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.

B
Bogdan, 2018-02-04
@Bogdan_dev

Try to work with collections and the foreach loop first, then go back to the iterator again and everything will immediately become clear to you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question