# How do i create a counter inside a loop in Hubspot?

**URL:** <https://community.hubspot.com/t/how-do-i-create-a-counter-inside-a-loop-in-hubspot/40385>\
**Category:** CMS Development\
**Created:** [July 8, 2021, 7:31am UTC](https://community.hubspot.com/t/how-do-i-create-a-counter-inside-a-loop-in-hubspot/40385 "2021-07-08T07:31:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JWiberg](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jwiberg/32/84489_2.png) [@JWiberg](https://community.hubspot.com/u/JWiberg)\
**Post date:** [July 8, 2021, 7:31am UTC](https://community.hubspot.com/t/how-do-i-create-a-counter-inside-a-loop-in-hubspot/40385/1 "2021-07-08T07:31:46Z")

</div>

Hey,

Im curious how i can create a counter inside a for loop in hubspot? I have a for loop that spit outs different links right now, but i need to be able to keep the count of how many iteration it does. How do i do it in HubL?  
For example in javascript you can keep track of it like this:

for (let i = 0; i \< 5; i++) {  
console.log(`Iteration number ${i}`);  
}

In the same way i want to create a function inside my for loop on my hubspot page where i can set i to a number and for each iteration it increases by 1. I hope this makes sense:)

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [July 8, 2021, 10:44am UTC](https://community.hubspot.com/t/how-do-i-create-a-counter-inside-a-loop-in-hubspot/40385/2 "2021-07-08T10:44:14Z")

</div>

loop.index  
i = i is defined ? i + 1 : 1  
loop.index0  
i = i is defined ? i + 1 : 0  
Backwards…  
loop.revindex  
i = i Is defined ? i - 1 : loop.length  
loop.revindex0  
i = i Is defined ? i - 1 : loop.length - 1

---

<div class="post-metadata">

**Author:** ![JWiberg](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jwiberg/32/84489_2.png) [@JWiberg](https://community.hubspot.com/u/JWiberg)\
**Post date:** [July 8, 2021, 11:22am UTC](https://community.hubspot.com/t/how-do-i-create-a-counter-inside-a-loop-in-hubspot/40385/3 "2021-07-08T11:22:37Z")

</div>

How would i put it in my code if my for loop looks like this?

```lia-code-sample
{% for item in items %}
Here goes the content for the loop...
{% endfor %}

```

---

<div class="post-metadata">

**Author:** ![NBaring](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/nbaring/32/2490_2.png) [@NBaring](https://community.hubspot.com/u/NBaring)\
**Post date:** [July 8, 2021, 11:45am UTC](https://community.hubspot.com/t/how-do-i-create-a-counter-inside-a-loop-in-hubspot/40385/4 "2021-07-08T11:45:45Z")

</div>

```lia-code-sample
 {% set items = ['one', 'two', 'three'] %}

 {% for item in items %}
 <h1>{{item}}</h1>
 <p>Iteration number {{loop.index}}</p>
 {% endfor %}

```
