I learned that for loops are create by
range (seq 20)
This starts a loop at 0. How can I start at 1?
I learned that for loops are create by
range (seq 20)
This starts a loop at 0. How can I start at 1?
That is correct, but you would then have to know that
range after 1 (seq 20)
will return 19 elements.
If you range with an index, I think it is less confusing to do something like this:
{{ range $index, $num := (seq 20) }}
$indexStartingAt1 := (add $index 1)
{{ end }}
In the above, both $indexStartingAt1 and $num will be 1,2,3 … 20.
And since both numbers now are equal, you can drop one of them:
{{ range (seq 20) }}
{{ . }}
{{ end }}
Will print 1…20.
very helpful, thank you!