digitalmars.D.learn - Any way to define variables from one scope in another scope?
- Ruby The Roobster (9/9) Jun 20 2022 Is there any way to define variables in an outer scope from an inner
- bauss (6/15) Jun 21 2022 No and it would only lead to bugs.
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
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