> For the complete documentation index, see [llms.txt](https://docs.uniot.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.uniot.io/platform/sandbox/visual-editor/loops.md).

# 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 %}
