D Documentation  
Foreach Statement
Foreach scans an array or hash. This means you could apply code for every element in an array or hash. It does this with a reference. It is also optional to store the refering index number or string (dependant on the hash key type).

static int[] intarray = [20, 40, 10, 23];
foreach(int index, int i; intarray)
{
  printf("%d: %d\n", index, i);
}
// equivelant to
for(int index = 0; index < intarray.length; index++)
{
  printf("%d: %d\n", index, intarray[index]);
}


In this example index is the index number, the value you'd place in brackets. I is the contained value at that index. To make it a reference which you can store back information to with modifying the array, use the 'inout' keyword.

The same thing works with string hashes.

int[char[]] map;
map["test"] = 10;
map["hello"] = 23;
foreach(char[] index, int value; map)
{
   printf("%.*s: %d\n", index, value);
}
Created using PHP docwiki written by Markus Dangl. Best viewed with Mozilla Firefox.