title: Twig Variable Scope in Loop
body: <p>From the <a href="http://twig.sensiolabs.org/doc/tags/set.html" rel="nofollow">twig documentation</a>: </p>
  
  <blockquote>
    <p>Note that loops are scoped in Twig; therefore a variable declared
    inside a for loop is not accessible outside the loop itself. If you
    want to access the variable, just declare it before the loop.</p>
  </blockquote>
  
  <p>Can someone explain why the following code:</p>
  
  <pre><code># Bundle/Resources/views/parent
  {% set id = 5 %}
  
  # Bundle/Resources/views/child
  {% extends 'Bundle::parent.html.twig' %}
  
  {%block one%}
      {% for item in threeitemarray %}
          {% set id = id + 1 %}
          {{id}}
      {%endfor%}
  {%endblock%}
  
  {%block two%}
      {% for item in threeitemarray %}
          {% set id = id + 1 %}
          {{id}}
      {%endfor%}
  {%endblock%}
  </code></pre>
  
  <p>returns 6, 7, 8, 6, 7, 8 instead of 6, 7, 8, 9, 10, 11?  How should I set it up to return the latter? </p>