title: Twig - Can I use variable in for loop condition?
body: <p>I am trying to create a layout from an array with Twig. My array has a depth of about seven nests and some keys have been dynamically added (so have different names) such as the time which is a direct child of "PLANNER" and "CLASS_" which has the ID appended to it.</p>
  
  <pre><code>"SCHEDULE": {
      "DAY": "FRIDAY",
      "PLANNER": {
          "830": {
              "CLASS_2231": {
                  "INSTRUCTOR": "TEACHER",
                  "CLASS_LEVEL": "PRIVATE",
                  "MAX_STUDENTS": "2",
                  "START_TIME": "830",
                  "FINISH_TIME": "900",
                  "STUDENTS": [
                      {
                          "STUDENT": {
                              "FIRST_NAME": "First Name",
                              "LAST_NAME": ""
                          }
                      },
                      {
                          "STUDENT": {
                              "FIRST_NAME": "First Name",
                              "LAST_NAME": ""
                          }
                      }
                  ]
              },
              "CLASS_1959": {
                  "INSTRUCTOR": "TEACHER",
                  "CLASS_LEVEL": "PRIVATE",
                  "MAX_STUDENTS": "1",
                  "START_TIME": "830",
                  "FINISH_TIME": "900",
                  "STUDENTS": [
                      {
                          "STUDENT": {
                              "FIRST_NAME": "First Name",
                              "LAST_NAME": ""
                          }
                      }
                  ]
              }
          },
          "900": {
              "CLASS_1742": {
                  "INSTRUCTOR": "TEACHER",
                  "CLASS_LEVEL": "DUCKLINGS",
                  "MAX_STUDENTS": "4",
                  "START_TIME": "900",
                  "FINISH_TIME": "930",
                  "STUDENTS": [
                      {
  </code></pre>
  
  <p>I have been trying to loop through this with the following code but it does seem to take variables (that have been set just before the next loop) as part of the for loop condition. However, it will print the variable in the nested loop (should I change the condition to let it run).</p>
  
  <pre><code>--EDITED
      {% for key, value in schedule.SCHEDULE.PLANNER %}
          &lt;div class="scheduleTimeTab"&gt;
              &lt;p&gt;{{ key }}&lt;/p&gt;
          &lt;/div&gt;
          {% set TIME = key %}
          {% for key, value in schedule.SCHEDULE.PLANNER.TIME %}
              &lt;div class="innerSchedule"&gt;
                  &lt;p&gt;{{ 'IS IT WORKING??' }}&lt;/p&gt;
              &lt;/div&gt;
          {% endfor %}
      {% endfor %}
  </code></pre>
  
  <p>I should also add that this code outputs this:</p>
  
  <pre><code>&lt;div class="scheduleContainer"&gt;
      &lt;div class="scheduleTimeTab"&gt;
          &lt;p&gt;830&lt;/p&gt;
      &lt;/div&gt;
      &lt;div class="scheduleTimeTab"&gt;
          &lt;p&gt;900&lt;/p&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Many thanks in advance
  Michael Z</p>