Loops - iamgio/quarkdown GitHub Wiki
For-each
The main type of loop is provided by the .foreach
function, which accepts:
- An
Iterable
value (Range
is iterable as well); - A 1-parameter lambda block, where the argument is the current item being iterated.
.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 of the input one, containing the evaluation of the lambda for each iterated value.
Thus, the function can be used as an expression:
.row alignment:{spacearound}
.foreach {1..3}
*.1* <!-- .1 is an implicit lambda argument: refers to the first parameter -->
Any iterable value is accepted. Here we use a Markdown list:
.var {letters}
- A
- B
- C
.foreach {.letters}
### .1
The letter is **.1**.
The type of iterated elements is preserved (see Typing for more):
.row alignment:{spacearound}
.foreach {1..5}
n:
.multiply {.n} by:{.n}
Repeat
The .repeat {times}
function is a shorthand for .foreach {1..times}
.
.repeat {3}
.1
1
2
3