# 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](https://docs.zerowork.io/using-zerowork/using-building-blocks/save-web-element/save-lists "mention").&#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="https://3220183989-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fg9LcR8XM7TGOzOCDGsCS%2Fuploads%2Fh0kaKTgiAC4H3UiUzORV%2FScreenshot%202023-11-23%20at%2010.38.13.png?alt=media&#x26;token=32db6731-d6ea-43b3-b6e5-4a7235ba784d" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3220183989-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fg9LcR8XM7TGOzOCDGsCS%2Fuploads%2FxfjNmNdqiRmKax1VADYn%2Fspaces_g9LcR8XM7TGOzOCDGsCS_uploads_oc9No5Y6EBdErf4glTUQ_Screenshot%202023-11-22%20at%2017.webp?alt=media&#x26;token=971479c9-17cd-4d85-aef1-d5660b247735" alt=""><figcaption></figcaption></figure>

Your main loop needs to loop through 30 pages.

<figure><img src="https://3220183989-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fg9LcR8XM7TGOzOCDGsCS%2Fuploads%2FcESqOq0lsORe5QzjWzCg%2FScreenshot%202023-11-23%20at%2010.43.09.png?alt=media&#x26;token=82c22a83-79bb-4222-b05f-13f982f33eff" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3220183989-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fg9LcR8XM7TGOzOCDGsCS%2Fuploads%2FzC9TUQU68Fhh3axRZvQE%2Fspaces_g9LcR8XM7TGOzOCDGsCS_uploads_nxkGq49PCC1CtEtu0mR6_Screenshot%202023-11-22%20at%2017.webp?alt=media&#x26;token=c0819981-adfe-4827-8df7-cd04a711d56a" 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="https://3220183989-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fg9LcR8XM7TGOzOCDGsCS%2Fuploads%2FvQ7NGJWs7DN5HUK8jlBo%2FScreenshot%202023-11-23%20at%2010.47.35.png?alt=media&#x26;token=f3ad3c5a-e393-4fc2-9500-ac2ada49e423" 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](https://docs.zerowork.io/using-zerowork/using-building-blocks/after-repeat "mention")) 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>" %}
