How do I output the last matrix block? I am pretty new to craft (just came from EE) and trying to output the last entry from a matrix field in my template: 

{% for block in entry.gallery.last() %}
    {% set image = block.image.first() %}
    &lt;img class="lazy" src="{{ siteUrl }}img/assets/loader.gif" data-src="{{ image.getUrl('galleryThumb') }}" data-src-retina="{{ image.getUrl('galleryThumbRetina') }}" alt="{{ image.title }}"&gt;
{% endfor %}


So this isn't working as I thought, i've done some snooping but have had no luck, any ideas?

Thanks
-Graham
Twig comes with a last filter which you should be able to use, so with your entry.gallery  you can do:

{% set lastBlock = entry.gallery|last %}


Which will return the last element in the sequence, there's more info in the twig docs:


  The last filter returns the last "element" of a sequence, a mapping, or a string:


Twig last filter