Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Perl
use 5.012; # each @array
while (my ($i, $x) = each @items) {
    print "array[$i] = $x\n";
}

The each iterator returns the index/key and value as a pair for each iteration.
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...