1
1
<!--
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 $
3
3
-->
4
4
5
5
<chapter id="plpgsql">
@@ -1779,10 +1779,10 @@ END IF;
1779
1779
</indexterm>
1780
1780
1781
1781
<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.
1786
1786
</para>
1787
1787
1788
1788
<sect3>
@@ -1807,30 +1807,36 @@ END LOOP;
1807
1807
<sect3>
1808
1808
<title><literal>EXIT</></title>
1809
1809
1810
+ <indexterm>
1811
+ <primary>EXIT</primary>
1812
+ <secondary>in PL/pgSQL</secondary>
1813
+ </indexterm>
1814
+
1810
1815
<synopsis>
1811
1816
EXIT <optional> <replaceable>label</replaceable> </optional> <optional> WHEN <replaceable>expression</replaceable> </optional>;
1812
1817
</synopsis>
1813
1818
1814
1819
<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</>.
1823
1827
</para>
1824
1828
1825
1829
<para>
1826
- If <literal>WHEN</> is present, 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</> is specified, the loop exit occurs only if
1831
+ <replaceable>expression</> is true. Otherwise, control passes
1832
+ to the statement after <literal>EXIT</>.
1829
1833
</para>
1830
1834
1831
1835
<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.
1834
1840
</para>
1835
1841
1836
1842
<para>
@@ -1858,9 +1864,61 @@ END;
1858
1864
</para>
1859
1865
</sect3>
1860
1866
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
+
1861
1914
<sect3>
1862
1915
<title><literal>WHILE</></title>
1863
1916
1917
+ <indexterm>
1918
+ <primary>WHILE</primary>
1919
+ <secondary>in PL/pgSQL</secondary>
1920
+ </indexterm>
1921
+
1864
1922
<synopsis>
1865
1923
<optional><<<replaceable>label</replaceable>>></optional>
1866
1924
WHILE <replaceable>expression</replaceable> LOOP
0 commit comments