Iterable
Anonymous contributor
Published Mar 15, 2024
Contribute to Docs
An iterable is a group of elements that can be retrieved sequentially. Dart uses the Iterable<E>
abstract class for representing iterable objects. The elements inside these objects can be traversed using the for-in
loop.
An iterable object consists of an iterator getter, which returns elements from the iterable object. The iterator is used for element traversal. Each time the iterator getter is accessed, a new iterator is returned by the iterable object. This means that more than one iterator can be returned by the same iterable object.
Example
In the following example, an iterable object is iterated over using the for-in
loop and its elements are printed to the terminal:
void main() {Iterable<int> iter = [12, 23, 34, 45, 56];for (var num in iter) {print(num);}}
Here is the output for the above code:
1223344556
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.