www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Any way to define variables from one scope in another scope?

reply Ruby The Roobster <rubytheroobster yandex.com> writes:
Is there any way to define variables in an outer scope from an inner 
scope?  I was thinking

```d
void main()
{
     int .y = 3;
}
```
would work, but it doesn't.
Jun 20 2022
parent bauss <jj_1337 live.dk> writes:
On Monday, 20 June 2022 at 13:56:04 UTC, Ruby The Roobster wrote:
 Is there any way to define variables in an outer scope from an 
 inner scope?  I was thinking

 ```d
 void main()
 {
     int .y = 3;
 }
 ```
 would work, but it doesn't.
No and it would only lead to bugs. If you have access to an inner scope then surely you have access to the outer scope and can just add the variable there. If you need to add a variable in a nested scope, then surely you're solving a problem with the wrong solution.
Jun 21 2022