Logo

Programming-Idioms

History of Idiom 7 > diff from v15 to v16

Edit summary for version 16 by :

Version 15

2015-08-20, 15:31:42

Version 16

2015-08-20, 15:32:13

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Imports
Imports
import std.stdio;
Code
foreach(i, x; items)
{
   writefln("%s: %s", i, x);
}
Code
foreach(i, x; items)
{
   writefln("%s: %s", i, x);
}
Comments bubble
use 'ref' on the item variable 'x' to access by reference
Comments bubble
use 'ref' on the item variable 'x' to access by reference