Bring back foreach int indexes

Steven Schveighoffer schveiguy at gmail.com
Wed Nov 29 22:30:30 UTC 2023


On Wednesday, 29 November 2023 at 21:47:09 UTC, bachmeier wrote:
>
> Yeah, but it's a matter of ugliness. This looks awful
>
> ```
> foreach(idx; 0..(cast(int) arr.length)) {
> }
> ```
>
> In the case you're talking about, you could do
>
> ```
> foreach(_idx, v; arr) {
>   int idx = cast(int) _idx;
> }
> ```
>
> I don't mind ugly and verbose code if there's sufficient 
> benefit. There's no benefit in this case.

Understand that I don't disagree with you. But my point is that 
`foreach(int i; 0 .. arr.length)` *never compiled*, whereas 
`foreach(int i, v; arr)` did compile (without deprecation) at 
some point.

This puts it in the category of "features that were removed", vs 
"features that should be added", and therefore gives a little 
less resistance to (re)allowing it.

-Steve


More information about the Digitalmars-d mailing list