# 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="https://3610933556-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtICyn0rKkxEa2DzPEdWY%2Fuploads%2FMwLySQrmGZiX9xX9Hg43%2Fimage.png?alt=media&#x26;token=cdaca600-d090-4049-93b5-ef46c40ba7e4" alt="">       </td><td><p><span data-gb-custom-inline data-tag="emoji" data-code="27a1">➡️</span></p><p> </p></td><td><img src="https://3610933556-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtICyn0rKkxEa2DzPEdWY%2Fuploads%2FbYmoIpAc3IxbUVLDYzN5%2Fimage.png?alt=media&#x26;token=84ad7378-6403-4556-8026-5b74c5b01c48" alt="" data-size="original"></td></tr></tbody></table>

&#x20;


---

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