> For the complete documentation index, see [llms.txt](https://docs.float16.cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.float16.cloud/prompting/loop.md).

# Loop

### Intro

LLMs have the ability to loop based on a modifier or condition to determine the action.

### How it work ?

LLMs can operate step by step. The number of loops can be defined by a specific number or can loop through the entire data.

```
food list = []

Add food name into food list 10 times.
```

{% hint style="info" %}
A software developer could consider this ability similar to the **Loop** functionality in other programming languages.
{% endhint %}

### Prompt example

{% embed url="<https://prompt.float16.cloud/prompt/e8c57ab1-73ce-4a7c-a816-9a69f239269f>" %}
Iterative add name of food
{% endembed %}

{% embed url="<https://prompt.float16.cloud/prompt/d1d2fe39-f3fc-4a0b-96b1-aebb75627dce>" %}
Iterative loop with condition
{% endembed %}

{% embed url="<https://prompt.float16.cloud/prompt/5832987b-1b91-4737-8b99-56aaab5a2a24>" %}
Iterative loop and stop (While loop)
{% endembed %}

{% embed url="<https://prompt.float16.cloud/prompt/51ee2c08-048c-43cd-af59-9cb9d3527fcc>" %}
Iterative loop and stop (For loop)
{% endembed %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.float16.cloud/prompting/loop.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
