View Single Post
03-11-13, 02:40 AM   #17
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Yes. The "=" isn't really important; only the "for ... do" parts. Any variables defined between "for" and "do" are automatically local to the scope that starts with "for" and ends with the corresponding "end".

Variables used in other types of loops are not automatically local, eg:

Code:
local i = 1
while i < 10 do
    -- i exists here
    i = i + 1
end
-- and it still exists here
Code:
local i = 1
repeat
    -- i exists here
    i = i + 1
until i == 10
-- and still here
Also:

Code:
local i = 1
for i = 1, 3 do
    print(i)
end
print(i)
... will print 1 2 3 1, since the "i" inside the loop is the one declared as part of the "for" statement, while the "i" that exists after the for-loop's "end" statement is the one explicitly defined as "local i" before the loop.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote