> For the complete documentation index, see [llms.txt](https://guide.docmaker.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://guide.docmaker.co/features/create-pdf-from-docx-template/build-your-docx-template/loops/nested-loops.md).

# Nested loops

docMaker lets you create nested loops, without any limit in terms of depth of the loops.

The nested loops feature is very useful when  you need to group your output by categories. They can be used inside tables or also for plain text, in order to repeat multiples lines inside main paragraphs.

Below is an example of this feature in a template.

The Bubble demo can be found here : [demo](https://docxtopdfplugintest.bubbleapps.io/version-test/nested_loops?debug_mode=true) | [editor](https://bubble.io/page?type=page\&name=nested_loops\&id=docxtopdfplugintest\&tab=tabs-1)

In order to do that, you will have to create a nested loops JSON and nested loops in your template.

```plaintext
{“orders” : [
 {
   "name": "Order1",
   "orderLines": [
     {
       "item_name": "trousers",
       "item_quantity": 1,
       "item_price": 100,
     },
     {
       "item_name": "shirt",
       "item_quantity": 50,
       "item_price": 50,
     },
     {
       "item_name": "shoes",
       "item_quantity": 1,
       "item_price": 1,
     },
   ]
 },
 {
   "name": "Order2",
   "orderLines": [
     {
       "item_name": "socks",
       "item_quantity": 1,
       "item_price": 33,
     }
   ]
 }
]
}
```

Copy

&#x20;

<table data-header-hidden><thead><tr><th></th><th width="44.333333333333314"></th><th></th></tr></thead><tbody><tr><td><strong>Template</strong></td><td> </td><td>Result</td></tr><tr><td><img src="/files/JJlKJg59rJj7VEf5Sx0F" alt="">       </td><td><p><span data-gb-custom-inline data-tag="emoji" data-code="27a1">➡️</span></p><p> </p></td><td><img src="/files/TloTunNzD26NUuovBdrG" alt="" data-size="original"></td></tr></tbody></table>

&#x20;


---

# 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:

```
GET https://guide.docmaker.co/features/create-pdf-from-docx-template/build-your-docx-template/loops/nested-loops.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.
