how to iterate on Array?

John Chapman via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jun 27 11:31:21 PDT 2015


On Saturday, 27 June 2015 at 17:43:13 UTC, aki wrote:
> I want to print the contents of Array!int
>
> import std.stdio;
> import std.container;
>
> void pr(Array!int a) {
> 	foreach(i, v; a[]) {
> 		writeln("%4s: %s\n", i, v);
> 	}
> }
>
> But when I compile it by DMD 2.062 on Windows
> it says:
>
> testArray.d(5): Error: cannot infer argument types
> (line 5 is at "foreach(i, v; a[]) {" )
>
> What's wrong? how can I iterate the array?
>
> Thanks, aki.

size_t i;
foreach (v; a[])
   writeln("%s: %s", i++, v);


More information about the Digitalmars-d-learn mailing list