<forLoop>
A tag that iterates a fixed number of times using a numeric counter. The current
counter value is stored as a dependency using the name specified by the var attribute.
The loop runs from begin (inclusive) to end (exclusive) with increments of step.
Negative step values are supported for counting down.
Attributes
| Name | Type | Description | Required | Default |
|---|---|---|---|---|
var |
String | The dependency key to store the current counter value. | Yes | - |
begin |
int | The starting value (inclusive). | No | 0 |
end |
int | The ending value (exclusive). | No | 0 |
step |
int | The increment per iteration. Cannot be zero. | No | 1 |
dependenciesScope |
String | How to scope dependencies: new, copy, or inherit. |
No | copy |
Examples
Basic Loop
<Column>
<forLoop var="i" begin="0" end="5">
<Text data="Item ${toString(i)}"/>
</forLoop>
</Column>
Produces: Item 0, Item 1, Item 2, Item 3, Item 4.
Custom Step
<Column>
<forLoop var="i" begin="0" end="10" step="2">
<Text data="${toString(i)}"/>
</forLoop>
</Column>
Produces: 0, 2, 4, 6, 8.
Counting Down
<Column>
<forLoop var="i" begin="5" end="0" step="-1">
<Text data="Countdown: ${toString(i)}"/>
</forLoop>
</Column>
Produces: Countdown: 5, Countdown: 4, Countdown: 3, Countdown: 2, Countdown: 1.
Generating Rows
<Column>
<forLoop var="row" begin="1" end="4">
<Row>
<forLoop var="col" begin="1" end="4">
<Container width="50" height="50">
<Text data="${toString(row)},${toString(col)}"/>
</Container>
</forLoop>
</Row>
</forLoop>
</Column>
See Also
<forEach>- For iterating over collections<if>/<else>- For conditional rendering