> For the complete documentation index, see [llms.txt](https://manis-organization-2.gitbook.io/untitled-1/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://manis-organization-2.gitbook.io/untitled-1/keywords/conditions-in-x3/break.md).

# break

In programming languages like X3, the "break" keyword is used within loops (such as "for" and "while" loops) to prematurely exit the loop when a certain condition is met. Here's how you would use the "break" keyword in your X3 language:

#### Basic Usage with "for" Loop:

```x3
# Using 'break' keyword in 'for' loop
for var i = 1 to 5 then
    if i == 3 then
        break  # Exit the loop when i is 3
    end
    show(i)
end
```

#### Explanation:

* In this example, the "for" loop iterates over the values from 1 to 5.
* When the loop variable `i` is equal to 3, the "break" keyword is encountered, causing the loop to terminate immediately.
* As a result, the loop stops executing, and the subsequent iterations are skipped.

#### Basic Usage with "while" Loop:

```x3
var i = 0

# Using 'break' keyword in 'while' loop
while i < 5 then
    i = i + 1
    if i == 3 then
        break  # Exit the loop when i is 3
    end
    show(i)
end
```

#### Explanation:

* In this example, the "while" loop continues to execute as long as the condition `i < 5` is true.
* Within each iteration, the loop variable `i` is incremented by 1.
* When `i` becomes equal to 3, the "break" keyword is encountered, causing the loop to terminate immediately.
* As a result, the loop stops executing, and the subsequent iterations are skipped.

#### Usage in Nested Loops:

```x3
# Using 'break' keyword in nested loops
for var i = 1 to 3 then
    for var j = 1 to 3 then
        if j == 2 then
            break  # Exit the inner loop when j is 2
        end
        show("({i}, {j})")
    end
end
```

#### Explanation:

* In this example, a nested "for" loop structure is used.
* When the inner loop variable `j` is equal to 2, the "break" keyword is encountered, causing the inner loop to terminate immediately.
* As a result, the inner loop stops executing, and the outer loop continues with its next iteration.

By incorporating the "break" keyword in your X3 language, you provide users with a way to prematurely exit loop constructs based on specific conditions. This capability allows for more flexible control flow within loops and enhances the efficiency of algorithmic implementations in X3 programs.


---

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