title: set variable Thymeleaf in a for each for a next condition
body: <p>everybody,</p>
  
  <p>I have a problem with Thymeleaf, I tried to set the variable "iterator" in my for: each.</p>
  
  <p>By default "iterator=0;" but if the condition is true I set the "iterator+1" but my variable is always 0 even the condition is true.</p>
  
  <p>I need this "iterator" for my next block condition because if the iterator ==1 i need to something show else in my view</p>
  
  <p>Here you can see my code:</p>
  
  <pre><code> &lt;div class="col-2"  th:each="t:${horaire.terrains}"&gt;
      &lt;h2 th:text="${t.nomTerrain}"&gt;&lt;/h2&gt;
      &lt;table border="1px"  &gt;
  
          &lt;tr  th:each="h,index : ${heures.subList(0,15)}"   &gt;
  
              &lt;td&gt;
  
         &lt;th:block th:each="resa:${reservations}"  
     th:if="${resa.dateReservation eq date &amp;&amp; resa.heureDebut eq h}"&gt;
  
  
                 &lt;a&gt;reserve&lt;/a&gt;
  
             &lt;p th:with="iterator=${iterator+1} "&gt;&lt;/p&gt;
             &lt;!--&lt;p th:text="${iterator}"&gt;&lt;/p&gt;--&gt;
  
         &lt;/th:block&gt;
  
                  &lt;th:block th:if="${iterator eq 0 }"&gt;
  
  
  
                      &lt;a th:text="${h}" th:href="@{addResa(heure=${h} , 
                     terrain=${t.id} ,date=${date},date2=${index.index+1}, 
                  listeHeures = ${heures} )}"&gt;&lt;/a&gt;
                  &lt;/th:block&gt;
  
  
              &lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;!--&lt;a th:text="${h}" th:href="@{addResa(heure=${h} , terrain=${t.id} 
          ,date=${date},date2=${index.index+1}, listeHeures = ${heures} )}"&gt; 
         &lt;/a&gt;--&gt;
  
  
      &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Here, in my controller, you can see the variable iterator:</p>
  
  <pre><code>    int iterator=0;
  
      model.addAttribute("iterator",iterator);
  </code></pre>