# to

In the context of the "for" loop in  X3 programming language, the "to" keyword is used to specify the range of values over which the loop variable iterates. Here's how you would use the "to" keyword in conjunction with the "for" loop:

#### Basic Usage:

```x3
# Using 'to' keyword in 'for' loop to specify the range
for var i = 1 to 5 then
    print(i)
end
```

#### Explanation:

* In this example, the "for" loop iterates over the values from 1 to 5 (inclusive).
* The loop variable `i` takes on each value within this range in sequential order, and the code inside the loop (printing the value of `i`) is executed for each iteration.

#### Step Size:

```x3
# Using 'to' with step size in 'for' loop
for var i = 0 to 10 step 2 then
    show(i)
end
```

#### Explanation:

* Here, the loop iterates over the values from 0 to 10 with a step size of 2.
* The loop variable `i` increments by 2 in each iteration, and the code inside the loop (printing the value of `i`) is executed.

#### Iterating Backwards:

```x3
# Using 'to' to iterate backwards in 'for' loop
for var i = 10 to 1 step -1 then
    show(i)
end
```

#### Explanation:

* This example demonstrates iterating backwards from 10 to 1 with a step size of -1.
* The loop variable `i` decrements by 1 in each iteration, and the code inside the loop (printing the value of `i`) is executed.

#### Nested Loops:

```x3
# Nested 'for' loops using 'to' keyword
for var i = 1 to 3 then
    for var j = 1 to 3 then
        show("({i}, {j})")
    end
end
```

#### Explanation:

* In this example, a nested "for" loop is used to create a grid-like structure.
* The outer loop iterates over the values of `i`, and for each iteration of `i`, the inner loop iterates over the values of `j`.

By incorporating the "to" keyword in your X3 language's "for" loop syntax, you provide users with a clear and concise way to specify the range of values over which they want to iterate.


---

# 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://manis-organization-2.gitbook.io/untitled-1/keywords/conditions-in-x3/to.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.
