Field Template Loop Counter Override Problem I'm using a template override for field.html.twig

I'm simply trying to generate a data-depth attribute that takes the index of the loop and multiplying it by 0.2.

Here is the Twig markup:

&lt;div{{ attributes.addClass(classes, 'field--items') }}&gt;
  {% for item in items %}
    {% set i = loop.index %}
    {% set depth = i * 0.2 %}
    &lt;div {{ item.attributes.addClass('field--item') }} {{ attributes.setAttribute('data-type', 'test') }} {{ attributes.setAttribute('data-depth', depth) }}&gt;
      {{ item.content }}
    &lt;/div&gt;
  {% endfor %}
&lt;/div&gt;


Here is the HTML output:

&lt;div data-quickedit-field-id="paragraph/2/field_test/en/default" class="field field--name-field-test-image field--type-image field--label-hidden field--items"&gt;
  &lt;div class="field--item" data-type="test" data-depth="0.2"&gt;
    &lt;img src="/sites/default/files/2016-08/5.png"&gt;
  &lt;/div&gt;
  &lt;div class="field--item" data-type="test" data-depth="0.2"&gt;
    &lt;img src="/sites/default/files/2016-08/4.png"&gt;
  &lt;/div&gt;
  &lt;div class="field--item" data-type="test" data-depth="0.4"&gt;
    &lt;img src="/sites/default/files/2016-08/3.png"&gt;
  &lt;/div&gt;
  &lt;div class="field--item" data-type="test" data-depth="0.6"&gt;       
    &lt;img src="/sites/default/files/2016-08/2.png"&gt;
  &lt;/div&gt;
  &lt;div class="field--item" data-type="test" data-depth="0.8"&gt;
    &lt;img src="/sites/default/files/2016-08/1.png"&gt;
  &lt;/div&gt;
&lt;/div&gt;


As you can see the first two iterations are the same - they have 0.2 as the data-depth which is incorrect it, the sequence should be 0.2, 0.4, 0.6, 0.8 and 1.0. Is this is a bug with drupal? Or am I totally missing something here. 

Thanks in advance.
I just tested this and it works for me:

   {% for item in items %}
        {% set counter = ( counter | default(0) ) + 0.2 %}
        &lt;div{{ item.attributes.addClass(item_classes) }} data-depth="{{ counter }}"&gt;{{ item.content }}&lt;/div&gt;
      {% endfor %}


This renders as:

&lt;div class="field field--name-field-gallery-ref" data-depth="0.2"&gt;
...
&lt;div class="field field--name-field-gallery-ref" data-depth="0.4"&gt;
...


Note, I did not get the repeating depth numbers as you did above.