Make foreach element optional
Steven Schveighoffer
schveiguy at gmail.com
Tue Mar 16 15:02:54 UTC 2021
On 3/16/21 8:49 AM, 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
Meh, is this a common need though? The first form isn't terrible.
In general, I'd say it would be nice to designate _ as an unused
variable (i.e. not allowed to access it, and it doesn't trigger
shadowing errors). It's like this in Swift for instance.
-Steve
More information about the Digitalmars-d-learn
mailing list