From ebcb4c931dc0ea5bc5e2199f39996f99fcab842b Mon Sep 17 00:00:00 2001 From: Neil Conway Date: Wed, 22 Jun 2005 01:35:03 +0000 Subject: Add a CONTINUE statement to PL/PgSQL, which can be used to begin the next iteration of a loop. Update documentation and add regression tests. Patch from Pavel Stehule, reviewed by Neil Conway. --- doc/src/sgml/plpgsql.sgml | 94 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 76 insertions(+), 18 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/plpgsql.sgml b/doc/src/sgml/plpgsql.sgml index b202bba7b44..e8d687928f8 100644 --- a/doc/src/sgml/plpgsql.sgml +++ b/doc/src/sgml/plpgsql.sgml @@ -1,5 +1,5 @@ @@ -1779,10 +1779,10 @@ END IF; - With the LOOP, EXIT, WHILE, - and FOR statements, you can arrange for your - PL/pgSQL function to repeat a series - of commands. + With the LOOP, EXIT, + CONTINUE, WHILE, and FOR + statements, you can arrange for your PL/pgSQL + function to repeat a series of commands. @@ -1807,30 +1807,36 @@ END LOOP; <literal>EXIT</> + + EXIT + in PL/pgSQL + + EXIT label WHEN expression ; - If no label is given, - the innermost loop is terminated and the - statement following END LOOP is executed next. - If label is given, it - must be the label of the current or some outer level of nested loop - or block. Then the named loop or block is terminated and control - continues with the statement after the loop's/block's corresponding - END. + If no label is given, the innermost + loop is terminated and the statement following END + LOOP is executed next. If label + is given, it must be the label of the current or some outer + level of nested loop or block. Then the named loop or block is + terminated and control continues with the statement after the + loop's/block's corresponding END. - If WHEN is present, loop exit occurs only if the specified - condition is true, otherwise control passes to the statement after - EXIT. + If WHEN is specified, the loop exit occurs only if + expression is true. Otherwise, control passes + to the statement after EXIT. - EXIT can be used to cause early exit from all types of - loops; it is not limited to use with unconditional loops. + EXIT can be used with all types of loops; it is + not limited to use with unconditional loops. When used with a + BEGIN block, EXIT passes + control to the next statement after the end of the block. @@ -1858,9 +1864,61 @@ END; + + <literal>CONTINUE</> + + + CONTINUE + in PL/pgSQL + + + +CONTINUE label WHEN expression ; + + + + If no label is given, the next iteration of + the innermost loop is begun. That is, control is passed back + to the loop control expression (if any), and the body of the + loop is re-evaluated. If label is present, it + specifies the label of the loop whose execution will be + continued. + + + + If WHEN is specified, the next iteration of the + loop is begun only if expression is + true. Otherwise, control passes to the statement after + CONTINUE. + + + + CONTINUE can be used with all types of loops; it + is not limited to use with unconditional loops. + + + + Examples: + +LOOP + -- some computations + EXIT WHEN count > 100; + CONTINUE WHEN count < 50; + -- some computations for count IN [50 .. 100] +END LOOP; + + + + + <literal>WHILE</> + + WHILE + in PL/pgSQL + + <<label>> WHILE expression LOOP -- cgit v1.2.3