<p>The code below ended up solving the issue for me.</p>

<pre><code>{% for row in 0..rows %}
</code></pre>

CC BY-SA 3.0
2016-09-09T14:28:10.473Z
2016-09-09T14:28:10.473Z
Rockwell Rice
<p>I am trying to develop a loop in a craft template that adjust the numbers of rows and awards per row based on the total number of awards.  The numbers are all coming back correct but I am struggling with getting the syntax of the loop correct. Below is the type of loop I am trying to execute.</p>

<pre><code>for ($i = 1; ; $i++) {
if ($i &gt; 10) {
  break;
}
  echo $i;
}
</code></pre>

<p>But I am getting errors because my syntax is not correct and I cannot seem to find this, although I realize I am probably either just missing it somewhere or not recognizing it.</p>

<p>I was trying something like this, along with other variations, but it keeps throwing errors.</p>

<pre><code>{% set exactRowsNeeded = count / 7 %} &lt;!-- correct --&gt;
{% set rows = ceil(exactRowsNeeded) %} &lt;!-- correct --&gt;
{% set exactAwardsPerRow = count / rows %} &lt;!-- correct --&gt;
{% set awardsPerRow = ceil(exactAwardsPerRow) %} &lt;!-- correct --&gt;

{% set r = 1 %}
{% for r %}
{% if r &lt;= 2 %} 
  {{ r }}
{% set r = r++ %}
{% endif %}
{% endfor %}
</code></pre>

<p>Here throws an error at the "for r" line.  It seems to be looking for something like "for r in rows" or something.  Even just a link to an example would be awesome I just cannot seem to get this syntax correct.</p>

<loop>
The twig syntax for this for loop
# The twig syntax for this for loop

(Asked by: username_0 on 2016-09-09)

I am trying to develop a loop in a craft template that adjust the numbers of rows and awards per row based on the total number of awards.  The numbers are all coming back correct but I am struggling with getting the syntax of the loop correct. Below is the type of loop I am trying to execute.
for ($i = 1; ; $i++) {
if ($i > 10) {
  break;
}
  echo $i;
}

But I am getting errors because my syntax is not correct and I cannot seem to find this, although I realize I am probably either just missing it somewhere or not recognizing it.
I was trying something like this, along with other variations, but it keeps throwing errors.
{% set exactRowsNeeded = count / 7 %} 
{% set rows = ceil(exactRowsNeeded) %} 
{% set exactAwardsPerRow = count / rows %} 
{% set awardsPerRow = ceil(exactAwardsPerRow) %} 

{% set r = 1 %}
{% for r %}
{% if r <= 2 %} 
  {{ r }}
{% set r = r++ %}
{% endif %}
{% endfor %}

Here throws an error at the "for r" line.  It seems to be looking for something like "for r in rows" or something.  Even just a link to an example would be awesome I just cannot seem to get this syntax correct.

**Tags:** loop

---

## 1 answers

### Answer by username_0 on 2016-09-09. Score: 2

The code below ended up solving the issue for me.
{% for row in 0..rows %}


---

