# For

A `for` flow allows a block of code to be executed once for each item in an array.  You can change the order of iteration by using array transformers such as `.sorted()` or `.reversed()` on the source data. Additionally, nested loops are fully supported.

{% hint style="info" %}
If you want to iterate over dictionary, use [`map`](/supernova-dsm/pulsar-language/flows/map.md) flow instead.
{% endhint %}

### Syntax

Basic syntax of `for` flow is as follows:

```swift
{[ for [property-name] in [statement] ]}
    Body, optionally using {{ value }}
{[/]}
```

With the following required attributes:

* `property-name` - the newly created property where iterated data is stored
* `statement` - statement to be evaluated to retrieve data for the iterator. Array is expected

For example, a `for` flow be used to create lists, menus, and similar structures from sourced data. Let's assume we have a variable `users` defined that contains following data:

```javascript
[{
    "name": "Jiri",
    "type": "member"
}, {
    "name": "Artem",
    "type": "admin"
},{
    "name": "Ydus",
    "type": "member" 
},{
    "name": "Oskar",
    "type": "visitor"
}
```

You can iterate on user data by defining a new variable `user` where each item in the array gets stored in each iteration:

```markup
<h1>Team Members</h1>
<ul>
    {[ for user in users ]}
    <li>{{ user.name.capitalized() }} ({{ user.type }})</li>
    {[/]}
</ul>
```

With each iteration, data in `user` is different, resulting in the following output:

```markup
<h1>Team Members</h1>
<ul>
    <li>JIRI (Member)</li>
    <li>ARTEM (Admin)</li>
    <li>YDUS (Member)</li>
    <li>OSKAR (Visitor)</li>
</ul>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://supernova-developers.gitbook.io/supernova-dsm/pulsar-language/flows/for.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
