All pages
Powered by GitBook
1 of 1

Loading...

WHILE

Execute a block while a condition is true. This loop construct checks a condition before each iteration and repeats the block as long as the condition holds.

Syntax

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

Description

The statement list within a WHILE statement is repeated as long as thesearch_condition is true. statement_list consists of one or more statements. If the loop must be executed at least once, can be used instead.

A WHILE statement can be . end_label cannot be given unless begin_label also is present. If both are present, they must be the same.

Examples

This page is licensed: GPLv2, originally from

CREATE PROCEDURE dowhile()
BEGIN
  DECLARE v1 INT DEFAULT 5;

  WHILE v1 > 0 DO
    ...
    SET v1 = v1 - 1;
  END WHILE;
END
REPEAT ... LOOP
labeled
fill_help_tables.sql