> For the complete documentation index, see [llms.txt](https://docs.zerowork.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zerowork.io/using-zerowork/using-building-blocks/start-repeat/nested-loops-handle-pagination.md).

# Nested Loops - Handle Pagination

You can use another *Start Repeat* building block inside of your loop. This is called nested loop (loop inside a loop). You can create as many nested loops within your main or other nested loops as you wish.

Its primary use case is to handle pagination.

#### **Example**: Save LinkedIn profile data from multiple pages - handle paginated results

Imagine you want to save a list of profiles from LinkedIn search results. LinkedIn usually shows 10 profiles per page. This is why you would need to set up a *Start Repeat* building block with a repetition number of 10. See example set-up here: [Save Lists](/using-zerowork/using-building-blocks/save-web-element/save-lists.md).&#x20;

But how do you make your TaskBot not just save 10 results from one page but go through, for example, 30 pages of results (making it a total of 300 collected profile links)?

For this or any other paginated results, you need a nested loop.&#x20;

Here is the workflow set-up:

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

*Open Link* opens the page where the list of profiles is displayed.

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

Your main loop needs to loop through 30 pages.

<figure><img src="/files/8fkaZacqVyjjHgmW7oBG" alt=""><figcaption></figcaption></figure>

Your nested loop will loop through profiles and save them, 10 per page.&#x20;

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

After your nested loop finishes saving 10 profiles, main loop continues via *After Repeat* with the action *Click*. Action click will click on the button "Next" and thus paginate to the next page.

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

Let's summarize the learnings:

* Loop is set up to repeat 30 times. This corresponds to the number of pages with search results on LinkedIn.
* Within every repetition, your TaskBot enters the nested loop and saves 10 profiles.
* After the nested loop is completed, the TaskBot continues (via [After Repeat](/using-zerowork/using-building-blocks/after-repeat.md)) with clicking "Next" button to go to the next page. Note that *After Repeat* must be placed after the **nested** *Start Repeat* block.&#x20;
* After that, the cycle repeats: Save 10 profiles, then click on "Next" - for 30 times.&#x20;

### Video Tutorial

{% embed url="<https://youtu.be/CJ2icDqWs9s?si=91KsfkMF5QgYjVG3>" %}
