🔁For
Just like with if
and switch
, corgi also provides a built-in for
-loop.
You can write anything behind the for
that you could also write behind a Go for
. Just don't add a {
.
Unlike Go templates, when writing a for-range loop the index goes first, just like in regular Go.
Ordered Map Iteration
When iterating over maps the order is non-deterministic, meaning the elements will appear in "random" order.
If you always want to print elements in the same (sorted) order, you can use corgi's ordered range
keyword, which allows you to range over maps with comparable keys (as defined by the comparable
constraint) in ascending order.
Last updated