access foreach index counter for Iterate n times

max haughton maxhaton at gmail.com
Sat May 21 02:29:47 UTC 2022


On Saturday, 21 May 2022 at 02:23:28 UTC, mw wrote:
> But isn't iota as a function call also expensive?

No.

https://d.godbolt.org/z/TsKbe96dv
> I wrote this naturally after seeing the array foreach example:
>
> ```
> foreach (i, e; 5 .. 10)
> ```
>
> I don't even know the function iota, and why it's needed for a 
> simple loop like this?
>
>
> ```
> foreach (e; 5 .. 10)
> ```
>
> just to get i?
>
> My point: the language should be more consistent.

I don't disagree.


More information about the Digitalmars-d mailing list