> For the complete documentation index, see [llms.txt](https://docs.pixiebrix.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pixiebrix.com/developing-mods/developer-concepts/control-flow/control-flow-bricks.md).

# Control Flow Bricks

[Release 1.7.0](/release-notes/release-notes-archive/release-1.7.0.md) (June 2022) introduced support for Control Flow bricks that “control” the order and sequence in which the bricks nested inside them run.

### Types of Control Flow Bricks

There are 4 primary control flow bricks: If-Else, For-Each, Try-Except, and Retry:

* **If-Else**: if a condition is met, run one the “if” branch of bricks, otherwise run the “else” branch of bricks
* **Try-Except**: run a “try” branch of bricks, recovering by running the “catch” branch of bricks if there’s an error or the user cancelled the run
* **Retry**: run a body of bricks, and re-run the body if there’s an error
* **For-Each**: for each element in a list/array, run a body of bricks, providing a different element to the body for each run

The Document Builder also uses control flow for the Button element handler, and the Brick element. The information on this page also applies to bricks you add to those elements.

{% hint style="info" %}
📖 When a Control Flow brick has multiple sub-sequences of bricks, we will call them “branches”. When a Control Flow brick contains a single sequence of bricks, we will call it the “body”.
{% endhint %}

In the Mod Overview, the Control Flow brick appears as a brick with a top/bottom section and one or more branches of bricks:

<figure><img src="https://2274778196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq123bF1HPQPV35s5vHa1%2Fuploads%2F33ctQwFsHkOkngd6Kwv8%2FUntitled%20(69).png?alt=media&amp;token=11889292-e431-4e2c-8ed4-fdb0006e8c58" alt=""><figcaption></figcaption></figure>

The If-Else brick. If the condition is true, PixieBrix will show confetti. If the condition is false, PixieBrix will show an alert.


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.pixiebrix.com/developing-mods/developer-concepts/control-flow/control-flow-bricks.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
