PLDB
Languages Features Calendar CSV Lists Blog About Sponsor Add Language
GitHub icon

Iterators

Iterators

Iterators are a feature.

In computer programming, an iterator is an object that enables a programmer to traverse a container, particularly lists.[1][2][3] Various types of iterators are often provided via a container's interface.


Languages with Iterators include Java, Python, C++, MATLAB, Ruby, Rust

Example from Java:
Iterator iter = list.iterator(); //Iterator<MyType> iter = list.iterator(); in J2SE 5.0 while (iter.hasNext()) { System.out.print(iter.next()); if (iter.hasNext()) System.out.print(", "); }
Example from Python:
https://www.w3schools.com/python/python_iterators.asp
Example from C++:
std::vector<int> items; items.push_back(5); // Append integer value '5' to vector 'items'. items.push_back(2); // Append integer value '2' to vector 'items'. items.push_back(9); // Append integer value '9' to vector 'items'. for (auto it = items.begin(); it != items.end(); ++it) { // Iterate through 'items'. std::cout << *it; // And print value of 'items' for current index. }
Example from MATLAB:
% Define an array of integers myArray = [1,3,5,7,11,13]; for n = myArray % ... do something with n disp(n) % Echo integer to Command Window end
Example from Ruby:
(0...42).each do |n| puts n end
Example from Rust:
for n in 0..42 { println!("{}", n); }
inheritance-feature.html 路 iterators-feature.html 路 mixin-feature.html

View source

PLDB - Build the next great programming language 路 v2022 Day 33 Docs Build Acknowledgements Traffic Today Traffic Trends Mirrors GitHub feedback@pldb.com