# ITERATE

## Syntax

```sql
ITERATE label
```

`ITERATE` can appear only within [LOOP](/docs/server/reference/sql-statements/programmatic-compound-statements/loop.md), [REPEAT](/docs/server/reference/sql-statements/programmatic-compound-statements/repeat-loop.md), and [WHILE](/docs/server/reference/sql-statements/programmatic-compound-statements/while.md) statements.`ITERATE` means "do the loop again", and uses the statement's [label](/docs/server/reference/sql-statements/programmatic-compound-statements/labels.md) to determine which statements to repeat. The label must be in the same stored program, not in a caller procedure.

If you try to use `ITERATE` with a non-existing label, or if the label is associated to a construct which is not a loop, the following error will be produced:

```sql
ERROR 1308 (42000): ITERATE with no matching label: <label_name>
```

Below is an example of how `ITERATE` might be used:

```sql
CREATE PROCEDURE doiterate(p1 INT)
BEGIN
  label1: LOOP
    SET p1 = p1 + 1;
    IF p1 < 10 THEN ITERATE label1; END IF;
    LEAVE label1;
  END LOOP label1;
  SET @x = p1;
END
```

## See Also

* [LEAVE](/docs/server/reference/sql-statements/programmatic-compound-statements/leave.md) - Exits a loop (or any labeled code block)

<sub>*This page is licensed: GPLv2, originally from*</sub> [<sub>*fill\_help\_tables.sql*</sub>](https://github.com/MariaDB/server/blob/main/scripts/fill_help_tables.sql)

{% @marketo/form formId="4316" %}


---

# 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://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/iterate.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.
