<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="repeat">
      </a>
      15.6.5.6 REPEAT Statement
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045176224336">
  </a>
  <a class="indexterm" name="idm46045176223264">
  </a>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa16177768"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token punctuation">[</span><em class="replaceable">begin_label</em>:<span class="token punctuation">]</span> <span class="token keyword">REPEAT</span>
    <em class="replaceable">statement_list</em>
<span class="token keyword">UNTIL</span> <em class="replaceable">search_condition</em>
<span class="token keyword">END</span> <span class="token keyword">REPEAT</span> <span class="token punctuation">[</span><em class="replaceable">end_label</em><span class="token punctuation">]</span></code></pre>
  </div>
  <p>
   The statement list within a
   <a class="link" href="repeat.html" title="15.6.5.6 REPEAT Statement">
    <code class="literal">
     REPEAT
    </code>
   </a>
   statement is repeated
        until the
   <em class="replaceable">
    <code>
     search_condition
    </code>
   </em>
   expression
        is true. Thus, a
   <a class="link" href="repeat.html" title="15.6.5.6 REPEAT Statement">
    <code class="literal">
     REPEAT
    </code>
   </a>
   always
        enters the loop at least once.
   <em class="replaceable">
    <code>
     statement_list
    </code>
   </em>
   consists of one or
        more statements, each terminated by a semicolon
        (
   <code class="literal">
    ;
   </code>
   ) statement delimiter.
  </p>
  <p>
   A
   <a class="link" href="repeat.html" title="15.6.5.6 REPEAT Statement">
    <code class="literal">
     REPEAT
    </code>
   </a>
   statement can be
        labeled. For the rules regarding label use, see
   <a class="xref" href="statement-labels.html" title="15.6.2 Statement Labels">
    Section 15.6.2, “Statement Labels”
   </a>
   .
  </p>
  <p>
   Example:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa46757851"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">delimiter</span> <span class="token comment" spellcheck="true">//</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">CREATE</span> <span class="token keyword">PROCEDURE</span> dorepeat<span class="token punctuation">(</span>p1 <span class="token datatype">INT</span><span class="token punctuation">)</span>
       <span class="token keyword">BEGIN</span>
         <span class="token keyword">SET</span> <span class="token variable">@x</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
         <span class="token keyword">REPEAT</span>
           <span class="token keyword">SET</span> <span class="token variable">@x</span> <span class="token operator">=</span> <span class="token variable">@x</span> <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">;</span>
         <span class="token keyword">UNTIL</span> <span class="token variable">@x</span> <span class="token operator">&gt;</span> p1 <span class="token keyword">END</span> <span class="token keyword">REPEAT</span><span class="token punctuation">;</span>
       <span class="token keyword">END</span>
       <span class="token comment" spellcheck="true">//</span>
<span class="token output">Query OK, 0 rows affected (0.00 sec)</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">CALL</span> dorepeat<span class="token punctuation">(</span><span class="token number">1000</span><span class="token punctuation">)</span><span class="token comment" spellcheck="true">//</span>
<span class="token output">Query OK, 0 rows affected (0.00 sec)</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token variable">@x</span><span class="token comment" spellcheck="true">//</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> @x   <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> 1001 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output">1 row in set (0.00 sec)</span></code></pre>
  </div>
 </div>
 <br/>
</div>
