11<!--
2- $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.73 2005/06/19 23:39:05 neilc Exp $
2+ $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.74 2005/06/22 01:35:02 neilc Exp $
33-->
44
55<chapter id="plpgsql">
@@ -1779,10 +1779,10 @@ END IF;
17791779 </indexterm>
17801780
17811781 <para>
1782- With the <literal>LOOP</>, <literal>EXIT</>, <literal>WHILE</>,
1783- and <literal>FOR </> statements, you can arrange for your
1784- <application>PL/pgSQL</application> function to repeat a series
1785- of commands.
1782+ With the <literal>LOOP</>, <literal>EXIT</>,
1783+ <literal>CONTINUE </>, <literal>WHILE</>, and <literal>FOR</>
1784+ statements, you can arrange for your <application>PL/pgSQL</>
1785+ function to repeat a series of commands.
17861786 </para>
17871787
17881788 <sect3>
@@ -1807,30 +1807,36 @@ END LOOP;
18071807 <sect3>
18081808 <title><literal>EXIT</></title>
18091809
1810+ <indexterm>
1811+ <primary>EXIT</primary>
1812+ <secondary>in PL/pgSQL</secondary>
1813+ </indexterm>
1814+
18101815<synopsis>
18111816EXIT <optional> <replaceable>label</replaceable> </optional> <optional> WHEN <replaceable>expression</replaceable> </optional>;
18121817</synopsis>
18131818
18141819 <para>
1815- If no <replaceable>label</replaceable> is given,
1816- the innermost loop is terminated and the
1817- statement following <literal>END LOOP</> is executed next.
1818- If <replaceable>label</replaceable> is given, it
1819- must be the label of the current or some outer level of nested loop
1820- or block. Then the named loop or block is terminated and control
1821- continues with the statement after the loop's/block's corresponding
1822- <literal>END</>.
1820+ If no <replaceable>label</replaceable> is given, the innermost
1821+ loop is terminated and the statement following <literal>END
1822+ LOOP</> is executed next. If <replaceable>label</replaceable>
1823+ is given, it must be the label of the current or some outer
1824+ level of nested loop or block. Then the named loop or block is
1825+ terminated and control continues with the statement after the
1826+ loop's/block's corresponding <literal>END</>.
18231827 </para>
18241828
18251829 <para>
1826- If <literal>WHEN</> ispresent, loop exit occurs only if the specified
1827- condition is true, otherwise control passes to the statement after
1828- <literal>EXIT</>.
1830+ If <literal>WHEN</> isspecified, the loop exit occurs only if
1831+ <replaceable>expression</> is true. Otherwise, control passes
1832+ to the statement after <literal>EXIT</>.
18291833 </para>
18301834
18311835 <para>
1832- <literal>EXIT</> can be used to cause early exit from all types of
1833- loops; it is not limited to use with unconditional loops.
1836+ <literal>EXIT</> can be used with all types of loops; it is
1837+ not limited to use with unconditional loops. When used with a
1838+ <literal>BEGIN</literal> block, <literal>EXIT</literal> passes
1839+ control to the next statement after the end of the block.
18341840 </para>
18351841
18361842 <para>
@@ -1858,9 +1864,61 @@ END;
18581864 </para>
18591865 </sect3>
18601866
1867+ <sect3>
1868+ <title><literal>CONTINUE</></title>
1869+
1870+ <indexterm>
1871+ <primary>CONTINUE</primary>
1872+ <secondary>in PL/pgSQL</secondary>
1873+ </indexterm>
1874+
1875+ <synopsis>
1876+ CONTINUE <optional> <replaceable>label</replaceable> </optional> <optional> WHEN <replaceable>expression</replaceable> </optional>;
1877+ </synopsis>
1878+
1879+ <para>
1880+ If no <replaceable>label</> is given, the next iteration of
1881+ the innermost loop is begun. That is, control is passed back
1882+ to the loop control expression (if any), and the body of the
1883+ loop is re-evaluated. If <replaceable>label</> is present, it
1884+ specifies the label of the loop whose execution will be
1885+ continued.
1886+ </para>
1887+
1888+ <para>
1889+ If <literal>WHEN</> is specified, the next iteration of the
1890+ loop is begun only if <replaceable>expression</> is
1891+ true. Otherwise, control passes to the statement after
1892+ <literal>CONTINUE</>.
1893+ </para>
1894+
1895+ <para>
1896+ <literal>CONTINUE</> can be used with all types of loops; it
1897+ is not limited to use with unconditional loops.
1898+ </para>
1899+
1900+ <para>
1901+ Examples:
1902+ <programlisting>
1903+ LOOP
1904+ -- some computations
1905+ EXIT WHEN count > 100;
1906+ CONTINUE WHEN count < 50;
1907+ -- some computations for count IN [50 .. 100]
1908+ END LOOP;
1909+ </programlisting>
1910+ </para>
1911+ </sect3>
1912+
1913+
18611914 <sect3>
18621915 <title><literal>WHILE</></title>
18631916
1917+ <indexterm>
1918+ <primary>WHILE</primary>
1919+ <secondary>in PL/pgSQL</secondary>
1920+ </indexterm>
1921+
18641922<synopsis>
18651923<optional><<<replaceable>label</replaceable>>></optional>
18661924WHILE <replaceable>expression</replaceable> LOOP