For iteration, I know there are different types of iterators E.g. Forward, Bidirectional, Random Access that can be used to access items in an array.
For enumeration, I've only heard about enums that can be used to index items. But are there terms called 'enumeration' or enumerator? If so then, What's the difference between iteration and enumeration?
The terminology is really tied to the language, and gets pretty confusing.
In C++, an "enumeration" (enum
) is a name, meaning "a bunch of numbered items", so there's no action going on; it's just a thing (like a class
).
And of course, "iteration" refers to an action, meaning "to repeat an action many times". Often, this is accompanied by going through a list of items.
But, in some languages, each one has a specific meaning as an action:
C#: Enumerators are objects that go through the items of a collection (like C++ iterators; IEnumerator<T>
). Iterators are methods that do pretty much the same thing, but in coroutine-style (yield return
).
C# still has enumerations (enum
s) like in C++.
Java: Iterators go through the items of a collection, like in C++. I'm not sure about "enumerators".
Java still has enumerations similar to C++, but they're sort of different as well.
Python: Iterators are like C# enumerators; generators are like C# iterators (yield
).
No enumerations, AFAIK.
etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With