Loop divisible by issue Code:

{% for block in entry.testimonials %}
  &lt;div class="col-24 {% if loop.last %}gutter-bottom{% else %}gutter-bottom--none{% endif %}"&gt;
    &lt;div class="section inner"&gt;
      &lt;div class="col-17 {% if loop.index0 is not divisible by(2) %}last float-right {% endif %}"&gt;
        {% switch block.type %}

        {% case "testimonials" %}

          &lt;h3&gt;{{ block.personsName }}&lt;/h3&gt;
          {{ block.quote }}
          &lt;/div&gt;

          {% for asset in block.image %}

            &lt;div class="col-7 circle-image-container {% if loop.index0 is divisible by(2) %}last{% endif %}"&gt;
              &lt;img src="{{ asset.getUrl() }}"  alt="{{ asset.title }}"/&gt;
            &lt;/div&gt;

          {% endfor %}

        {% endswitch %}
    &lt;/div&gt;
  &lt;/div&gt;
{% endfor %}   


Can anyone point out why the...

loop.index0 is divisible by(2)


I have on the div around the image isn't working. I'm getting the 'last' class on everything. The one on the previous div is working fine.

What am I missing?

EDIT:

I've just realised it's in it's own image loop causing the problem. How can I get around this?
Forgive me if I'm wrong... by using loop.index0 is divisible by(2) are you trying to determine if the instance is odd or even?


1st - returns false
2nd - returns true
3rd - returns false
4th - returns true


If so Twig does support checking if the loop index is even or odd. Perhaps that would be better to use?

{% if loop.index is even %}Even{% endif %}


EDIT

I've just had a read of the Craft docs for the Case and Switch tags and found this:


  If you’re using the {% switch %} tag inside of a {% for %} loop, you won’t be able to access Twig’s loop variable directly inside of the {% switch %} tag. Instead, you can access it like so:


{% for matrixBlock in entry.matrixField %}
    {% set loopIndex = loop.index %}

    {% switch matrixBlock.type %}

        {% case "text" %}

            Loop #{{ loopIndex }}

    {% endswitch %}
{% endfor %}