<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="while">
      </a>
      15.6.5.8 WHILE Statement
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045176185760">
  </a>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa49666477"><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">WHILE</span> <em class="replaceable">search_condition</em> <span class="token keyword">DO</span>
    <em class="replaceable">statement_list</em>
<span class="token keyword">END</span> <span class="token keyword">WHILE</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="while.html" title="15.6.5.8 WHILE Statement">
    <code class="literal">
     WHILE
    </code>
   </a>
   statement is repeated as long as the
   <em class="replaceable">
    <code>
     search_condition
    </code>
   </em>
   expression is true.
   <em class="replaceable">
    <code>
     statement_list
    </code>
   </em>
   consists of one or
        more SQL statements, each terminated by a semicolon
        (
   <code class="literal">
    ;
   </code>
   ) statement delimiter.
  </p>
  <p>
   A
   <a class="link" href="while.html" title="15.6.5.8 WHILE Statement">
    <code class="literal">
     WHILE
    </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="sa8920080"><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 keyword">CREATE</span> <span class="token keyword">PROCEDURE</span> dowhile<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">BEGIN</span>
  <span class="token keyword">DECLARE</span> v1 <span class="token datatype">INT</span> <span class="token keyword">DEFAULT</span> <span class="token number">5</span><span class="token punctuation">;</span>

  <span class="token keyword">WHILE</span> v1 <span class="token operator">&gt;</span> <span class="token number">0</span> <span class="token keyword">DO</span>
    <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
    <span class="token keyword">SET</span> v1 <span class="token operator">=</span> v1 <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">;</span>
  <span class="token keyword">END</span> <span class="token keyword">WHILE</span><span class="token punctuation">;</span>
<span class="token keyword">END</span><span class="token punctuation">;</span></code></pre>
  </div>
 </div>
 <br/>
</div>
