> For the complete documentation index, see [llms.txt](https://docs.wem.io/platform/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wem.io/platform/wemtipsandtricks/performance/the-split-loop.md).

# The Split Loop

The Split loop is used to split a text value and store each part separately as rows in a list in the database. This method can be used to separate a row of a CSV document, break-up date values and split other character separated texts.&#x20;

To achieve this a custom loop needs to be created with the split function at its core:&#x20;

### Data model:

* Create a transient numeric field called *Index* to keep track of the current item.
* Create a numeric *ItemCount* field to count the number of items resulting from the split.
* \[*Input.Text*] field, which provides the text value that needs to be divided into rows.&#x20;

### Flowchart:&#x20;

* Set *Index* to 1 to reset the current split part to the first item.
* Set *ItemCount* to the number of items resulting from the split function: \
  `count(split([Input.Text], ';'))`.
* Check if *ItemCount* is more than zero; this is important to avoid an endless loop when Index and *ItemCount* never meet.
* Add or go to the row where current value needs to be saved.&#x20;
* Assign the current value to the correct field with the following function: `count(split([Input.Text], ';'))(Misc.Index)` \
  The (*Misc.Index*) chooses the split part that needs to be assigned.&#x20;
* Add 1 to the *Index* to process the next item;
* Check if the *Index* is less than or equal to the *ItemCount*:\
  `[Misc.Index] <= [Misc.ItemCount]`
* When *ItemCount* is less then the index the decision node results in true and goes back to the add  or go to row node to repeat the loop.&#x20;
* When Index is greater than *ItemCount*, all split items are added, and you can leave the loop to save your changes and exit the flow.

### Example:

<figure><img src="/files/fQmtJCc09xtnedO0r748" alt=""><figcaption></figcaption></figure>


---

# 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://docs.wem.io/platform/wemtipsandtricks/performance/the-split-loop.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.
