Skip to content

Add until and untilStep

Compare
Choose a tag to compare
@technosophos technosophos released this 16 Aug 22:09
· 427 commits to master since this release

This release adds two functions: until and untilStep. These functions generate integer slices. They are designed to be used for iteration:

{{range $i, $val := until 5}}{{end}}

In the above, $i is the index, and $val is the value. Both will iterate from 0 to 4.

For more control, you may use untilStep. The above can be replicated exactly:

{{range $i, $val := until 0 5 1}}{{end}}

untilStep takes three arguments: untilStep $start $end $step:

  • $start: The starting value
  • $end: The end value
  • $step: The increment value

Here's an example that will produce even numbers less than 10:

{{range $i, $val := until 0 10 2}}
  {{$val}}
{{end}}

The above will produce

0
2
4
6
8