Make foreach element optional

Imperatorn johan_forsberg_86 at hotmail.com
Tue Mar 16 13:31:34 UTC 2021


On Tuesday, 16 March 2021 at 12:49:13 UTC, Per Nordlöw wrote:
> I find myself writing
>
> foreach (_; 0 .. n)
>     doSomething(); // no using the variable `_`
>
> .
>
> What about relaxing the syntax to allow
>
>     foreach (; 0 .. n)
>
> and/or
>
>     foreach (0 .. n)
>
> ?
>
> Thereby making the `ForeachTypeList` of `AggregateForeach` in 
> the grammar rule [1] optional.
>
> [1] https://dlang.org/spec/statement.html#foreach-statement

foreach(0..n) could work. Why though.


More information about the Digitalmars-d-learn mailing list