Django break statement not allowed in block tags

Error message: “django.template.exceptions.TemplateSyntaxError: Invalid block tag on line 82: ‘break’, expected ‘elif’, ‘else’ or ‘endif’. Did you forget to register or load this tag?”

This error is being caused because I am trying to use the break statement in a block tag in a Django template.

To fix this error, I replace it with a return statement from the block tag. Which will terminate the if statement immediately. But the error remains the same.

My goal is to stop the for loops after listing 5 items from the category, Please I need help to fix this issue
Here is the code:

<div class="card">
                <h5 class="mb-30">By Categories</h5>
                <div class="categories-dropdown-wrap font-heading">
                  <ul>
                    {% for c in categories %}
                      <li>
                        <input
                          data-filter="category"
                          class="form-check-input filter-checkbox"
                          type="checkbox"
                          name="checkbox"
                          id="exampleCheckbox2"
                          value="{{ c.id }}"
                        />
                        &nbsp;&nbsp;
                        <a href="{% url 'core:category-product-list' c.cid %}">
                          <img src="{{c.image.url}}" alt="" />{{ c.title }}</a
                        >
                      </li>
                      {% if c.loop.index == 5 %}
                        <li>
                          <p>This is the 5th category.</p>
                        </li>
                        {% break %}
                      {% endif %}
                    {% endfor %}
                  </ul>
                </div>
              </div>

There is no break tag. (See Built-in template tags and filters | Django documentation | Django)

If you want to limit your iterations, then trim the number of entries being added in the context. (Apply the limit in the view, not the template.)

I only what to limit it to a few places, not the entire function for example the category list on the sidebar can have only 5 while the category list page has the full list.
How can I achieve that

See the slice filter.

Thanks its solve

{% for c in categories|slice:":5" %}
                      <li>
                        <input
                          data-filter="category"
                          class="form-check-input filter-checkbox"
                          type="checkbox"
                          name="checkbox"
                          id="exampleCheckbox2"
                          value="{{ c.id }}"
                        />
                        &nbsp;&nbsp;
                        <a href="{% url 'core:category-product-list' c.cid %}">
                          <img src="{{c.image.url}}" alt="" />{{ c.title }}</a
                        >
                      </li>
                    {% endfor %}