# Control Flow

The contents of a Linx function is executed from top to bottom.

<figure><img src="/files/YQvdn2YUx6mPuydfUAox" alt="Default Control Flow"><figcaption></figcaption></figure>

In Linx control flow statements are implemented as functions. The Linx plugin contains DoWhile, ForEach, IfElse and TryCatch. They work exactly like their programming counterparts.

ForEach loops through any list and exposes each item in an execution path. To try it:

1. Create a list and call it Names.
2. Drag a ForEach from the Linx plugin.
3. Set the List property to Names (using the dropdown).

<figure><img src="/files/Z5C0vAG8k7JGGse1nXq0" alt="ForEach Function"><figcaption></figcaption></figure>

The ForEach shows an execution path called Loop. This path will be executed once for each item in the List. To see it working:

1. Add a couple of items to Names.
2. Add the File plugin.
3. Drag the TextFileWrite function into the box below Loop.
4. Set the File path property.
5. Set the Contents property to ForEach.Loop by selecting it from the dropdown.

<figure><img src="/files/Z5C0vAG8k7JGGse1nXq0" alt="ForEach Loop"><figcaption></figcaption></figure>

Click DEBUG to run the Function and see the result.

DoWhile and IfElse use expressions to control the program flow. To try DoWhile:

1. Add an Integer to the Function and name it Counter.
2. Add a DoWhile and set its Condition property to Counter < 5. Use the Expression Editor in the dropdown to make this easier. DoWhile will keep on executing while the Condition is true.
3. Add a SetValue to the Loop and set its properties to add 1 to Counter each time it executes.

<figure><img src="/files/5Nxx63dFcy3ClKZ0wRss" alt="ForEach Loop"><figcaption></figcaption></figure>

Click DEBUG to run the Function and see the result.

***

{% embed url="<https://youtu.be/DAAaDlQOoYk>" %}


---

# 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://docs.linx.software/main-concepts/control-flow.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.
