title: Scope of a local variable in a block
body: <p>If I have:</p>
  
  <pre><code>2.times do
    i ||= 1
    print "#{i} "
    i += 1
    print "#{i} "
  end
  </code></pre>
  
  <p>I get <code>1 2 1 2</code>, whereas I was expecting <code>1 2 2 3</code>. Why does <code>i</code> lose its assignment when the loop starts over? It behaves as expected if the assignment occurs outside the loop, so I guess it has to do with scope, but I didn't realize loops have their own scopes. Can someone clarify?</p>
  
  <p><em>Update:</em> Thanks for the help on this. Part of my confusion stemmed from coming to Ruby from Python, which doesn't have block scope (I think). </p>