Bring back foreach int indexes

Nick Treleaven nick at geany.org
Fri Dec 1 12:20:54 UTC 2023


On Thursday, 30 November 2023 at 11:01:15 UTC, Hipreme wrote:
> That is because there is no reason to have explicit conversions 
> everywhere, they are overly verbose and ugly. And this is one 
> of the reasons because I don't use `foreach` in my code. Good 
> old `for` loop can let you decide the type. Modern programming 
> languages should reduce friction, and not increase it.

Modern languages should detect bugs:

```d
for (ubyte i = 0; i != a.length; i++) {}
```
The above compiles without error, but never terminates if `a` has 
 > 255 elements.

```d
foreach (ubyte i; 0 .. a.length) {} // compile error
```


More information about the Digitalmars-d mailing list