title: In Lua, should I define a variable every iteration of a loop or before the loop?
body: <p>Specifically in Lua, will I do any harm by doing this:</p>
  
  <pre><code>for i = 1, 10 do
      local foo = bar()
      -- do stuff with foo
  end
  </code></pre>
  
  <p>instead of this:</p>
  
  <pre><code>local foo
  for i = 1, 10 do
      foo = bar()
      -- do stuff with foo
  end
  </code></pre>
  
  <p>I mean, will Lua try to allocate new memory for <code>foo</code> every iteration? Could the first block lead to slower execution?</p>