29 posts
Location
Colorado, USA
Posted 30 September 2012 - 04:05 AM
Which way is better? Is there a difference?
local foo
while true do
foo = fooFunction()
end
while true do
local foo = fooFunction()
end
839 posts
Location
England
Posted 30 September 2012 - 04:17 AM
Ok, I have no clue what you are getting at.
You're trying to give a function a different name to run by?
I'm getting the feeling you read ahead a bit and have confused yourself (either way you've confused me).
In short, can you make the question a bit clearer, with more detail?
1688 posts
Location
'MURICA
Posted 30 September 2012 - 05:06 AM
It actually depends on the situation. If you need to access foo outside of the while loop, the first option is your best bet. However if the variable is unique to only the while loop, and you don't need it anywhere else, it's better to localize it inside of the loop.
29 posts
Location
Colorado, USA
Posted 30 September 2012 - 11:56 AM
Sorry, yeah that was a bit unclear. My question was is there any difference in performance.
I think
this stackoverflow post might have answered my question.
And thanks Kingdaro. I didn't know you could localize a variable to inside a loop. Testing shows me that in the second example foo is nil after the loop ends.
2447 posts
Posted 30 September 2012 - 12:15 PM
As far as I understand it there is a small performance penalty from localising it over and over. Hence the first way would be better.
However we are probably talking milliseconds if even that!