> ## Documentation Index
> Fetch the complete documentation index at: https://docs.upsolve.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# ITERATE

## Synopsis

```text theme={null}
ITERATE label
```

## Description

The `ITERATE` statement allows processing of blocks in [SQL
routines](/sql/routines/introduction) to move processing back to the start of a
context block. Contexts are defined by a [`label`](/sql/routines/introduction#labels). If no label
is found, the functions fails with an error message.

## Examples

```sql theme={null}
FUNCTION count()
RETURNS bigint
BEGIN
  DECLARE a int DEFAULT 0;
  DECLARE b int DEFAULT 0;
  top: REPEAT
    SET a = a + 1;
    IF a <= 3 THEN
        ITERATE top;
    END IF;
    SET b = b + 1;
  RETURN b;
END
```

Further examples of varying complexity that cover usage of the `ITERATE`
statement in combination with other statements are available in the [SQL
routines examples documentation](/sql/routines/examples).

## See also

* [routines](/sql/routines/introduction)
* [leave](/sql/routines/leave)
