---
slug: /while
---

# WHILE

The `WHILE` statement is used to construct basic conditional statements.

The syntax of the `WHILE` statement is as follows:

```sql
[begin_label:] WHILE search_condition DO
    statement_list
END WHILE [end_label]
```

The `statement_list` in the `WHILE` statement is repeatedly executed as long as the `search_condition` expression is True. The `statement_list` consists of one or more SQL statements, each of which ends with a semicolon (;). You can use a `label` to mark the `WHILE` statement.

Here is an example of the `WHILE` statement:

```sql
DELIMITER //

CREATE PROCEDURE while_proc()
   BEGIN
     DECLARE v1 INT DEFAULT 10;
     WHILE v1 > 0 DO
       SET v1 = v1 - 1;
     END WHILE;
   END //
Query OK, 0 rows affected
```