access foreach index counter for Iterate n times

Ali Çehreli acehreli at yahoo.com
Sat May 21 02:40:06 UTC 2022


On 5/20/22 19:23, mw wrote:

 > But isn't iota as a function call also expensive?

I am sure someone will show some disassembly to compare. :)

 > I wrote this naturally after seeing the array foreach example:
 >
 > ```
 > foreach (i, e; 5 .. 10)
 > ```

The biggest issue there is the number range, which is a weird thing in 
the language.

 > My point: the language should be more consistent.

The automatic loop counter is available only for arrays. If we see 
number ranges things other than arrays (they are not arrays), then there 
is no consistency issue.

One could argue to remove number ranges from the language but I don't 
think it's that big of a deal.

Ali



More information about the Digitalmars-d mailing list