The main type of loop is provided by the .foreach function, which accepts:
Iterable value.foreach {2..4}
n:
The number is: **.n**The number is: 2
The number is: 3
The number is: 4
The function returns an ordered iterable collection of the same size as the input, containing the evaluation of the lambda for each iterated value. This means the function can be used as an expression, similarly to the map function in many programming languages.
Keep in mind that .1 implicitly refers to the first parameter of the lambda.
.row alignment:{spacearound}
.foreach {1..3}
.11
2
3
Any iterable value is accepted, including Markdown lists. See Iterable for all possible ways of defining an iterable value.
.var {letters}
- A
- B
- C
.foreach {.letters}
###! .1
The letter is **.1**.The letter is A.
The letter is B.
The letter is C.
The type of iterated elements is preserved. See Typing for more information.
.row alignment:{spacearound}
.foreach {1..5}
n:
.multiply {.n} by:{.n}1
4
9
16
25
The .repeat {times} function is a shorthand for .foreach {1..times}.
.repeat {3}
.11
2
3