Wouldn't the compiler be smart with this shadowing variable?
frame
frame86 at live.com
Sat Dec 11 20:22:13 UTC 2021
On Saturday, 11 December 2021 at 15:15:06 UTC, Matheus wrote:
>
> I'm just a bit intrigued by your last sentence. Is there
> anything evil this may result or anything that I should be
> aware of?
Besides it looks like an error, you may think that it just
introduces a scope which can be referenced by the for-loop but
this only works in the initialization section. See what happens
if you want to do more steps at iteration for this fancy looking
syntax:
```d
// iteration works, but scope behind does nothing
for({int i=0; j=0;} i<10; ++i, {++i; ++j;} ){}
// endless loop
for({int i=0; j=0;} i<10; {++i; ++j;} ){}
```
Not sure if bug or feature but it is inconsistent for me and thus
a reason to avoid it.
More information about the Digitalmars-d-learn
mailing list