.docname {Loops}
.include {docs}

## For-each

The main type of loop is provided by the **`.foreach`** function, which accepts:
1. An [`Iterable`](iterable.qd) value
2. A single-parameter [lambda](lambda.qd) block, where the argument is the current item being iterated

.examplemirror
    .foreach {2..4}
        n:
        The number is: **.n**

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.

.examplemirror {Keep in mind that `\.1` implicitly refers to the first parameter of the lambda.}
    .row alignment:{spacearound}
        .foreach {1..3}
            .1

Any iterable value is accepted, including Markdown lists. See [*Iterable*](iterable.qd) for all possible ways of defining an iterable value.

.examplemirror
    .var {letters}
      - A
      - B
      - C

    .foreach {.letters}
      ###! .1

      The letter is **.1**.

The type of iterated elements is preserved. See [*Typing*](typing.qd) for more information.

.examplemirror
    .row alignment:{spacearound} 
        .foreach {1..5}
            n:
            .multiply {.n} by:{.n}

## Repeat

The **`.repeat {times}`** function is a shorthand for `.foreach {1..times}`.

.examplemirror
    .repeat {3}
        .1