foreach loop

Namal via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Nov 3 07:05:59 PST 2015


On Tuesday, 3 November 2015 at 14:52:19 UTC, Adam D. Ruppe wrote:
> On Tuesday, 3 November 2015 at 14:47:14 UTC, Namal wrote:
>> I remember it is possible to get the index for each element in 
>> the foreach loop, but I forgot how to do it. Can you help me 
>> out please. Thx.
>
> for many of them it is as simple as:
>
> foreach(index, element; array) { }

Thank you. I am still struggling with the functional ways of D. 
Now how could I write this foreach loop the functional way?

bool[] arr = [ture, false, ture, ...];

int count;
foreach(i;arr){

   if(!i)
     count++;
}
writeln(count);




More information about the Digitalmars-d-learn mailing list