//Iterating over any object type
while iterator.hasNext()
print(iterator.next());
//Iterating over numbers
Sum = 0
while iterator.hasNext()
sum = sum + iterator.next();
While iterator.hasNext() doAnything(iterator.next());
10 20 30 40
10 get(0) 20 get(1) 30 get(2) 40 get(3)
10 get(0) 20 get(1) 30 get(2) 40 get(3)
Name | Type | Description |
---|---|---|
DynArrayIterator | Class | The class to code |
array | DynamicArray | ivar that we send "get" to |
nextIndex | int | ivar that we use for "get" and that we increment |
list = [10, 20, 30, 40] iter = new Iterator(list) index = 0 while (iter.hasNext()) Test that iter.next() equals list[index] index++