Create a dynamic select element I want to build a dynamic html select element that includes the prior five years, given the current year. So, since it is now 2020, the result would be:

&lt;select&gt;
&lt;option value="2015"&gt;2015&lt;/option&gt;
.
.
&lt;option value="2019"&gt;2019&lt;/option&gt;




Basically want a "loop while" function, but Twig does not do that. I know I did something like this once before with a macro, but can't for the life of me remember and can't find anything on Stack Exchange. 

I know I could do it with Javascript, but would prefer to use Twig. Have the feeling I am missing something obvious, just not obvious to me!
You can do something like this (with lots of refactoring possible):

{% set thisYear = now | date("Y") %}
{% set startYear = thisYear - 1 %}
{% set endYear = startYear - 4 %}

{% set yearRange = startYear..endYear %}

&lt;select name=""&gt;
{% for year in yearRange %}
    &lt;option value="{{ year }}"&gt;{{ year }}&lt;/option&gt;
{% endfor %}
&lt;/select&gt;