Wouldn't the compiler be smart with this shadowing variable?

frame frame86 at live.com
Sat Dec 11 01:02:36 UTC 2021


On Friday, 10 December 2021 at 13:35:37 UTC, Matheus wrote:

> I mean this is a bit weird, imagine I have different "for 
> loops" and in this situation I'll need to do this:
>
> j=0;
> for(int i=0;i<10;++i){}
>
> Otherwise:
>
> for(i=0,j=0;i<10;++i){}
>
> This works, but now "i" variable will be out of the "for loop" 
> scope.
>
> Matheus.

You probably want this:

```d
int j;
for({int i=0; j=0;} i<10; ++i){}
```

Beware, this syntax comes directly from hell


More information about the Digitalmars-d-learn mailing list