> For the complete documentation index, see [llms.txt](https://wwydev.gitbook.io/mkdc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wwydev.gitbook.io/mkdc/zhi-nan/xun-huan.md).

# Loop

### define loop variables

Define a loop variable in the JSON file, which should be of type array\[json]

{% code title="main.json" %}

```json
{
    "variable": "hello world",
    "loop": [{"name": "content1", "is_show":true},{"name": "content2","is_show": false},{"name": "content3", "is_show": true}]
}
```

{% endcode %}

### use loop

To use loops in a markdown file, it is necessary to start with the "for-" or "forn-" directive and start with "<--- {end}--->" end.

Instructions in the loop can all parse local parameters in the for variable.

Note: "forn-" followed by an integer represents the number of cycles

{% code title="main.md" %}

```markdown
<!--{for-loop}-->
# <!--{v-name}-->
<!--{if-is_show}-->
hello world
<!--{end}-->
<!--{end}-->

<!--{forn-6}-->
hello world
<!--{end}-->
```

{% endcode %}

### compiler results

{% code title="dist/build.md" %}

```markdown
# content1
hello world
# content2

# content3
hello world

hello world
hello world
hello world
hello world
hello world
hello world
```

{% endcode %}
