# Loops

Loop blocks repeatedly execute code, eliminating the need to duplicate instructions. Use loops to process multiple sensor readings, generate patterns, handle collections of data, or create sequences of operations.

## repeat

<div align="left"><figure><img src="/files/mUHn7GunwKKEB0qYL8re" alt=""><figcaption></figcaption></figure></div>

Executes the enclosed code a fixed number of times. Use this when you know exactly how many iterations you need.

**Parameters:**

* **Count** (Number): Number of times to repeat

**Example:**

<div align="left"><figure><img src="/files/ZrCLJleCayKbNRdPwsjJ" alt=""><figcaption><p>Average sensor reading</p></figcaption></figure></div>

## repeat while

<div align="left"><figure><img src="/files/0yz2XLEE4V7bAbguU13j" alt=""><figcaption></figcaption></figure></div>

Repeats code as long as the condition remains true. The condition is checked before each iteration.

**Parameters:**

* **Condition** (Boolean): The condition to evaluate before each iteration

**Example:**

<div align="left"><figure><img src="/files/U21wNei3iacfmrgJJSBe" alt=""><figcaption><p>Process values while above threshold</p></figcaption></figure></div>

## repeat until

<div align="left"><figure><img src="/files/6kvIvDPZBdBAk7U3uxwV" alt=""><figcaption></figcaption></figure></div>

Repeats code until the condition becomes true. The condition is checked after each iteration, so the loop always executes at least once.

**Parameters:**

* **Condition** (Boolean): The condition to evaluate after each iteration

**Example:**

<div align="left"><figure><img src="/files/631caaG9RryllE19725A" alt=""><figcaption><p>Read until valid value received</p></figcaption></figure></div>

## iterator

<div align="left"><figure><img src="/files/gZS8LczE06iZd2yC1ulL" alt=""><figcaption></figcaption></figure></div>

Returns the current iteration counter for the loop, starting from 0. Use this to create indexed operations or patterns.

**Returns:**

* **Number**: The current loop iteration (0, 1, 2, ...)

**Example:**

<div align="left"><figure><img src="/files/45lNd4VuTOE0DLgUQMym" alt=""><figcaption><p>Alternate on/off pattern for multiple LEDs</p></figcaption></figure></div>

{% hint style="warning" %}
This block only works inside a loop block. Using it elsewhere will cause an error.

<img src="/files/35T5GA0ftZXf6vDnIqMN" alt="" data-size="original">
{% endhint %}


---

# 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://docs.uniot.io/platform/sandbox/visual-editor/loops.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.
