# Loops

### While Loops

While loops will be executed WHILE the condition is still true.

{% code lineNumbers="true" %}

```
while true == true then
    log("True is equal to true (No way!).")
end
```

{% endcode %}

### For Loops

For loops will repeat a block of code for a set number of times. It will count a variable from a start point to an end one. An optional step controls how much the counter changes iteration (default is 1, use a negative step to count down).

{% code lineNumbers="true" %}

```
-- Count up from 1 to 5
for i = 1, 5 then
  log(i)
end

-- Count down from 10 to 0 by 2
for i = 10, 0, -2 then
  log(i)
end
```

{% endcode %}


---

# 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://control-blocks-mod.gitbook.io/control-blocks-mod-docs/controlscript/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.
