I’m getting someone unexpected behavior with the range function and upon searching I found this unit test page. If I paste the following in the template designer
{% for i in range(5, 10) %}{{ i }} {% endfor %}
It yields
5 6 7 8 9
Which matches the output shown on the page’s Jinja2 section. My question is why is this returning one less than the right-most element passed to the range function?
It’s normal for arrays, lists and other such structures to start at 0, but I can’t think of a single language where your start a counter at 1 and it reverts to 0. E.g. in C#
for (int i=1;i <=10;i ++)
Write(i);
Would print the following because i is initialized to start at 1.