# \[SOLVED\] How do I (for) loop in a html template?

**URL:** <https://discourse.gohugo.io/t/solved-how-do-i-for-loop-in-a-html-template/3628>\
**Category:** support\
**Created:** [July 6, 2016, 12:46am UTC](https://discourse.gohugo.io/t/solved-how-do-i-for-loop-in-a-html-template/3628 "2016-07-06T00:46:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![yuzroz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/yuzroz/32/1791_2.png) [@yuzroz](https://discourse.gohugo.io/u/yuzroz)\
**Post date:** [July 6, 2016, 12:46am UTC](https://discourse.gohugo.io/t/solved-how-do-i-for-loop-in-a-html-template/3628/1 "2016-07-06T00:46:33Z")

</div>

Hi,  
I wonder what is the nicest way to emulate for loop in html template. Sorry to ask such a basic question, but google search doesn’t help in this case. Thanks!

```auto
for i = 0; i < 5; i++ {
   ...
}

```

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [July 6, 2016, 8:28am UTC](https://discourse.gohugo.io/t/solved-how-do-i-for-loop-in-a-html-template/3628/2 "2016-07-06T08:28:00Z")

</div>

Go templates has no traditional for loop.

You have to `range` over a list.

The closest thing in Hugo:

```auto
{{ range $i, $sequence := (seq 5) }}
{{ $i }}: {{ $sequence }}
{{ end }}

```

The above should print:

```auto
0: 1
1: 2
2: 3
3: 4
4: 5

```

---

<div class="post-metadata">

**Author:** ![yuzroz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/yuzroz/32/1791_2.png) [@yuzroz](https://discourse.gohugo.io/u/yuzroz)\
**Post date:** [July 6, 2016, 11:24pm UTC](https://discourse.gohugo.io/t/solved-how-do-i-for-loop-in-a-html-template/3628/3 "2016-07-06T23:24:29Z")

</div>

This works great, thanks!

---

<div class="post-metadata">

**Author:** ![frank](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@frank](https://discourse.gohugo.io/u/frank)\
**Post date:** [March 22, 2017, 12:00am UTC](https://discourse.gohugo.io/t/solved-how-do-i-for-loop-in-a-html-template/3628/4 "2017-03-22T00:00:01Z")

</div>

Is the seq function documented somewhere?

---

<div class="post-metadata">

**Author:** ![rdwatters](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rdwatters/32/2848_2.png) [@rdwatters](https://discourse.gohugo.io/u/rdwatters)\
**Post date:** [March 22, 2017, 12:07am UTC](https://discourse.gohugo.io/t/solved-how-do-i-for-loop-in-a-html-template/3628/5 "2017-03-22T00:07:24Z")

</div>

[https://hugodocs.info/functions/seq/](https://hugodocs.info/functions/seq/)

---

<div class="post-metadata">

**Author:** ![shubhangi\_lokhande](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@shubhangi\_lokhande](https://discourse.gohugo.io/u/shubhangi_lokhande)\
**Post date:** [February 8, 2018, 7:23am UTC](https://discourse.gohugo.io/t/solved-how-do-i-for-loop-in-a-html-template/3628/6 "2018-02-08T07:23:48Z")

</div>

where it should be use? in script or in head?plzzzz ans ASAP

---

<div class="post-metadata">

**Author:** ![jijomp](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@jijomp](https://discourse.gohugo.io/u/jijomp)\
**Post date:** [January 1, 2020, 9:17am UTC](https://discourse.gohugo.io/t/solved-how-do-i-for-loop-in-a-html-template/3628/7 "2020-01-01T09:17:54Z")

</div>

> [@bep](#):
>
> {{ range $i, $sequence := (seq 5) }} {{ $i }}: {{ $sequence }} {{ end }}

Thanks for the same. It works for me.

---

<div class="post-metadata">

**Author:** ![maiki](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/maiki/32/16384_2.png) [@maiki](https://discourse.gohugo.io/u/maiki)\
**Post date:** [January 2, 2020, 9:17am UTC](https://discourse.gohugo.io/t/solved-how-do-i-for-loop-in-a-html-template/3628/8 "2020-01-02T09:17:57Z")

</div>

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
