<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="statement-labels">
      </a>
      15.6.2 Statement Labels
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045176479376">
  </a>
  <a class="indexterm" name="idm46045176477888">
  </a>
  <a class="indexterm" name="idm46045176476400">
  </a>
  <a class="indexterm" name="idm46045176474912">
  </a>
  <a class="indexterm" name="idm46045176473424">
  </a>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa459480"><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">BEGIN</span>
    <span class="token punctuation">[</span><em class="replaceable">statement_list</em><span class="token punctuation">]</span>
<span class="token keyword">END</span> <span class="token punctuation">[</span><em class="replaceable">end_label</em><span class="token punctuation">]</span>

<span class="token punctuation">[</span><em class="replaceable">begin_label</em>:<span class="token punctuation">]</span> <span class="token keyword">LOOP</span>
    <em class="replaceable">statement_list</em>
<span class="token keyword">END</span> <span class="token keyword">LOOP</span> <span class="token punctuation">[</span><em class="replaceable">end_label</em><span class="token punctuation">]</span>

<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>

<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>
   Labels are permitted for
   <a class="link" href="begin-end.html" title="15.6.1 BEGIN ... END Compound Statement">
    <code class="literal">
     BEGIN ... END
    </code>
   </a>
   blocks and for the
   <a class="link" href="loop.html" title="15.6.5.5 LOOP Statement">
    <code class="literal">
     LOOP
    </code>
   </a>
   ,
   <a class="link" href="repeat.html" title="15.6.5.6 REPEAT Statement">
    <code class="literal">
     REPEAT
    </code>
   </a>
   , and
   <a class="link" href="while.html" title="15.6.5.8 WHILE Statement">
    <code class="literal">
     WHILE
    </code>
   </a>
   statements. Label use for
      those statements follows these rules:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <em class="replaceable">
       <code>
        begin_label
       </code>
      </em>
      must be followed by a
          colon.
     </p>
    </li>
    <li class="listitem">
     <p>
      <em class="replaceable">
       <code>
        begin_label
       </code>
      </em>
      can be given without
      <em class="replaceable">
       <code>
        end_label
       </code>
      </em>
      . If
      <em class="replaceable">
       <code>
        end_label
       </code>
      </em>
      is present, it must be
          the same as
      <em class="replaceable">
       <code>
        begin_label
       </code>
      </em>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      <em class="replaceable">
       <code>
        end_label
       </code>
      </em>
      cannot be given without
      <em class="replaceable">
       <code>
        begin_label
       </code>
      </em>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      Labels at the same nesting level must be distinct.
     </p>
    </li>
    <li class="listitem">
     <p>
      Labels can be up to 16 characters long.
     </p>
    </li>
   </ul>
  </div>
  <p>
   To refer to a label within the labeled construct, use an
   <a class="link" href="iterate.html" title="15.6.5.3 ITERATE Statement">
    <code class="literal">
     ITERATE
    </code>
   </a>
   or
   <a class="link" href="leave.html" title="15.6.5.4 LEAVE Statement">
    <code class="literal">
     LEAVE
    </code>
   </a>
   statement. The following
      example uses those statements to continue iterating or terminate
      the loop:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa41440835"><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> doiterate<span class="token punctuation">(</span>p1 <span class="token datatype">INT</span><span class="token punctuation">)</span>
<span class="token keyword">BEGIN</span>
  label1: <span class="token keyword">LOOP</span>
    <span class="token keyword">SET</span> p1 <span class="token operator">=</span> p1 <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">;</span>
    <span class="token keyword">IF</span> p1 <span class="token operator">&lt;</span> <span class="token number">10</span> <span class="token keyword">THEN</span> <span class="token keyword">ITERATE</span> label1<span class="token punctuation">;</span> <span class="token keyword">END</span> <span class="token keyword">IF</span><span class="token punctuation">;</span>
    <span class="token keyword">LEAVE</span> label1<span class="token punctuation">;</span>
  <span class="token keyword">END</span> <span class="token keyword">LOOP</span> label1<span class="token punctuation">;</span>
<span class="token keyword">END</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   The scope of a block label does not include the code for handlers
      declared within the block. For details, see
   <a class="xref" href="declare-handler.html" title="15.6.7.2 DECLARE ... HANDLER Statement">
    Section 15.6.7.2, “DECLARE ... HANDLER Statement”
   </a>
   .
  </p>
 </div>
 <br/>
</div>
