@for

Repeats its body. The implicit attribute n is a non-negative count (@for:3), an inclusive range (@for:0..6) that iterates upward, or a tabular dataset (@for:#islands), which iterates its rows top to bottom. Inside the body {{i}} splices the counter — the 1-based row number over a dataset — and over a dataset {{i.<column>}} splices that row's cell; as: renames both halves. Ranges must ascend — a descending from..to is a compile error.

@forDirective

#Attributes

nRequiredImplicit
How many times, or over what: a non-negative integer count (@for:3), an inclusive from..to range (@for:0..6) that iterates upward, or a tabular dataset by reference (@for:#islands, @for:#statistics.faithful for a pack's), whose rows it walks in order. The dataset must be declared ABOVE the loop, and naming a column (#islands.area) is a compile error — loop over the dataset and write {{i.area}}. A geo dataset has no rows, and an attached file this build cannot read is refused rather than run zero times.
number | interval | reference
Can be written as shorthand: @for:value
as
Names the binding — as: k makes the splice {{k}} instead of {{i}} — which is how nested loops tell theirs apart. Over a dataset it renames both halves: {{row}} and {{row.area}}. Must be a valid identifier.

#Allowed content

Body { }The content to repeat — spliced once per iteration with {{i}} (and, over a dataset, {{i.column}}) substituted

#Examples

@for:0..4{
    point(x: {{i}}; y: {{i}})
}
@for(n: 1..3; as: k){
    Attempt {{k}} of 3.
}
@data#islands{
    island | area
    Baltra | 25.09
    Bartolome | 1.24
}

@for:#islands{
    {{i}}. {{i.island}} covers {{i.area}} km$^2$.
}
@for(n: #soil; as: row){
    line#trace-{{row}}(x: 1, 2, 3; y: {{row.a}}, {{row.b}}, {{row.c}})
}

Last updated