Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Java
import static java.lang.System.out;
import static java.util.stream.IntStream.range;
range(0, items.length)
    .forEach(i -> {
        out.println(i + " = " + items[i]);
    });
import static java.lang.System.out;
int i, n;
for (i = 0, n = items.size(); i < n; ++i)
    out.println(i + " = " + items.get(i));

items is a List.
import static java.lang.System.out;
int i = 0;
for (T t : items)
    out.println(i++ + " = " + t);

items must be of type, `Iterable`, or an array.
import static java.lang.System.out;
int i, n;
for (i = 0, n = items.length; i < n; ++i)
    out.println(i + " = " + items[i]);

items is an array.
with Ada.Text_IO;
use Ada.Text_IO;
for I in Items'Range loop
   X := Items (I);
   Put_Line (Integer'Image (I) & " " & Integer'Image (X));
end loop;

Assuming Items is an array of integers.

New implementation...