- var myHash:Hash<Int> = new Hash();
- myHash.set("one", 1);
- myHash.set("two", 1);
- myHash.set("three", 2);
- myHash.set("four", 3);
- myHash.set("five", 5);
- var total:Int = 0;
- for ( num in myHash.iterator() ) {
- total += num;
- trace(num + ": " + total);
- }
In computer science, an iterator is an object that allows a programmer to traverse through all the elements of a collection, regardless of its specific implementation. An iterator is sometimes called a cursor, especially within the context of a database.
– From Wikipedia –
In this particular example you don’t need to use .iterator() as the Hash class is iterable, see http://haxe.org/ref/iterators > ‘Iterable Objects’.
NOTE: Use myHash.iterator() (mind the parenthesis) and not myHash.iterator as I’m used to from coding AS3.