Loop break

I want to be able to exit a loop in a template/shortcode when a specific condition is fulfilled. For example, exit a range loop after locating the desired item. Using {{ break }} in the loop results in a function "break" not defined error.
I found Hugo discourse issue While - break-in Hugo, and the related golang issue #20531. This issue was resolved only recently, on 17 Oct 2017, by adding support for {{ break }} and {{ continue }} (done in golang commit 3be5d55). I’m using the latest 0.30.2 version of Hugo, which was released on 19 Oct 2017.
–> Will {{ break }} and {{ continue }} be supported in the next version of Hugo?

It will be supported in the next version after the date Go 1.10 is released.

1 Like

Hi Bjorn. I see that [Hugo v0.37|https://github.com/gohugoio/hugo/releases/tag/v0.37] supports Go v1.10. So are the {{ break }} and {{ continue }} loop statements supported in Hugo v0.37+?

(Feel free to also point out additional advantages of Go 1.10 that we might be able to use to improve our Hugo development :-).)


Those statements are not in Go 1.10 (was pulled out at the last minute).

Very disappointing … . Do you know whether these statements planned to be added in a future Go release?

I want this as well. It feels very limiting not being able to do this.

Hi Bjorn, big fan of Hugo. Do you plan to add the break or continue statements in the future? Thanks!

As per the associated issue at the main Go repository, support for break and continue was reverted and the issue has been left open and unresolved.

I am archiving this old topic.