range.rst 720B

123456789101112131415161718192021222324252627282930313233343536373839
  1. ``range``
  2. =========
  3. Returns a list containing an arithmetic progression of integers:
  4. .. code-block:: jinja
  5. {% for i in range(0, 3) %}
  6. {{ i }},
  7. {% endfor %}
  8. {# returns 0, 1, 2, 3 #}
  9. When step is given (as the third parameter), it specifies the increment (or
  10. decrement):
  11. .. code-block:: jinja
  12. {% for i in range(0, 6, 2) %}
  13. {{ i }},
  14. {% endfor %}
  15. {# returns 0, 2, 4, 6 #}
  16. The Twig built-in ``..`` operator is just syntactic sugar for the ``range``
  17. function (with a step of 1):
  18. .. code-block:: jinja
  19. {% for i in 0..3 %}
  20. {{ i }},
  21. {% endfor %}
  22. .. tip::
  23. The ``range`` function works as the native PHP `range`_ function.
  24. .. _`range`: http://php.net/range