For Loops in Assume-Global Functions

Discuss the future of the AutoHotkey language
Ursi
Posts: 18
Joined: 16 Oct 2018, 14:11
GitHub: Ursi

For Loops in Assume-Global Functions

16 Oct 2018, 21:41

In "for k, v in obj", v2 is supposed to localize k and v, which personally I think is the way to go. I was actually really surprised when I found out v1.1 didn't do this. However, "for" loops in an assume-global function still make k and v global variables. Is this the intended effect? If so, I vote to keep the behaviour consistent.
Ursi
Posts: 18
Joined: 16 Oct 2018, 14:11
GitHub: Ursi

Re: For Loops in Assume-Global Functions

16 Oct 2018, 23:35

Perhaps I'm mistaken and they do perform the same... I thought I tested it and saw that k and v didn't show up on the global variables list when a for loop is used in the main script body, but it looks like I was wrong...
Helgef
Posts: 3226
Joined: 17 Jul 2016, 01:02
Contact:

Re: For Loops in Assume-Global Functions

17 Oct 2018, 04:05

In "for k, v in obj", v2 is supposed to localize k and v
The word localize might have been used in the docs at some point, I can't find it now. There shouldn't be any confusion now,
When the loop breaks or completes, these variables are restored to their former values.
It works.

You should use local appropriately, as you do for any other variables.

Cheers.

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: No registered users and 3 guests