Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Java
import java.util.Iterator;
T t;
Iterator<T> i = items.iterator();
while (i.hasNext()) {
    t = i.next();
}
for (Item x: items) {
    doSomething(x);
}

This syntax is allowed since Java 5.
It works with arrays or collections as well.
Item is the type of the elements.
T t;
Iterator<T> i = items.listIterator();
while (i.hasNext()) {
    t = i.next();
}

The `ListIterator` allows for backward iteration, and mutation.
for(int i=0;i<items.length;i++){
	doSomething( items[i] );
}

This syntax is now "old-school" since the foreach construct introduced in Java 5.
items.stream().forEach(item -> doSomething(item));

This syntax uses the streams api introduced in Java 8.
for (T x : items) {}
for Item of Items loop
   Do_Something (Item);
end loop;

New implementation...