# Unexpected assignment

**URL:** <https://discourse.gohugo.io/t/unexpected-assignment/41153>\
**Category:** support\
**Created:** [October 28, 2022, 11:27pm UTC](https://discourse.gohugo.io/t/unexpected-assignment/41153 "2022-10-28T23:27:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [October 28, 2022, 11:27pm UTC](https://discourse.gohugo.io/t/unexpected-assignment/41153/1 "2022-10-28T23:27:57Z")

</div>

This works as expected

```nohighlight
{{ $i := 0 }}
{{ range $i = slice 1 2 3 }}
{{ end }}
{{ $i }} --> 3

```

This also works as expected

```nohighlight
{{ $x := 0 }}
{{ $i := 0 }}
{{ range $i = slice 1 2 3 }}
{{ end }}
{{ $i }} --> 3

```

But if you reverse the order of the first two lines:

```nohighlight
{{ $i := 0 }}
{{ $x := 0 }}
{{ range $i = slice 1 2 3 }}
{{ end }}
{{ $i }} --> [1 2 3] (this should be 3, not a slice)

```

I didn’t expect this result. Are my expectations unreasonable?

Tested with v0.105.0 and v0.54.0… same results.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [October 30, 2022, 8:59pm UTC](https://discourse.gohugo.io/t/unexpected-assignment/41153/2 "2022-10-30T20:59:12Z")

</div>

[https://github.com/golang/go/issues/56490](https://github.com/golang/go/issues/56490)

[https://github.com/gohugoio/hugo/issues/10411](https://github.com/gohugoio/hugo/issues/10411)
