# Loop range format quick question

**URL:** <https://forum.ansible.com/t/loop-range-format-quick-question/32852>\
**Category:** Ansible Project\
**Created:** [May 5, 2020, 12:36pm UTC](https://forum.ansible.com/t/loop-range-format-quick-question/32852 "2020-05-05T12:36:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave\_Zarei](https://avatars.discourse-cdn.com/v4/letter/d/ee59a6/32.png) [@Dave\_Zarei](https://forum.ansible.com/u/Dave_Zarei)\
**Post date:** [May 5, 2020, 12:36pm UTC](https://forum.ansible.com/t/loop-range-format-quick-question/32852/1 "2020-05-05T12:36:28Z")

</div>

HI,

quick question about how to use a variable in loop range:

I got this:

loop: “{{range (0, 2+1) | list}}”

and this is what i want to use:

loop: “{{range (0, myvariable +1) | list}}”

where “myvaribale” contains number 2

but it comes back with an error when i run it, i also tried to put myvariable in double quote, single quote, but no help, is there any specific format to put myvariable in here?

Thanks,  
Dave.

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [May 5, 2020, 12:53pm UTC](https://forum.ansible.com/t/loop-range-format-quick-question/32852/2 "2020-05-05T12:53:22Z")

</div>

> HI,
> 
> quick question about how to use a variable in loop range:
> 
> I got this:
> 
> loop: "{{range (0, 2+1) | list}}"
> 
> and this is what i want to use:
> 
> loop: "{{range (0, myvariable +1) | list}}"
> 
> where "myvaribale" contains number 2
> 
> but it comes back with an error when i run it, i also tried to put myvariable in double quote, single quote, but no  
> help, is there any specific format to put myvariable in here?

You might need to use myvariable | int as Jinja results are strings - but it is always helpful to post the error with  
your question.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Dave\_Zarei](https://avatars.discourse-cdn.com/v4/letter/d/ee59a6/32.png) [@Dave\_Zarei](https://forum.ansible.com/u/Dave_Zarei)\
**Post date:** [May 8, 2020, 4:35pm UTC](https://forum.ansible.com/t/loop-range-format-quick-question/32852/3 "2020-05-08T16:35:16Z")

</div>

Thanks Stefan, used the following and it’s working like you said:

loop: “{{range (0, myvariable | int +1) | list}}”
