sequence of statements so long as the condition expression
evaluates to true. The condition is checked just before
each entry to the loop body.
<synopsis>
<optional><<label>></optional>
WHILE <replaceable>expression</replaceable> LOOP
<replaceable>statements</replaceable>
END LOOP;
</synopsis>
The WHILE statement repeats a
sequence of statements so long as the condition expression
evaluates to true. The condition is checked just before
each entry to the loop body.
</para>
<para>
For example:
<programlisting>
WHILE amount_owed > 0 AND gift_certificate_balance > 0 LOOP
...
...
@@ -1288,25 +1307,22 @@ WHILE NOT boolean_expression LOOP
END LOOP;
</programlisting>
</para>
</listitem>
</varlistentry>
</sect3>
<varlistentry>
<term>
FOR
</term>
<sect3>
<title>FOR (integer for-loop)</title>
<listitem>
<para>
<synopsis>
<optional><<label>></optional>
FOR <replaceable>name</replaceable> IN <optional> REVERSE </optional> <replaceable>expression</replaceable> .. <replaceable>expression</replaceable> LOOP
<replaceable>statements</replaceable>
END LOOP;
</synopsis>
A loop that iterates over a range of integer values. The variable
<replaceable>name</replaceable> is automatically created as type
This form of FOR creates a loop that iterates over a range of integer
values. The variable
<replaceable>name</replaceable> is automatically defined as type
integer and exists only inside the loop. The two expressions giving
the lower and upper bound of the range are evaluated once when entering
the loop. The iteration step is normally 1, but is -1 when REVERSE is
...
...
@@ -1327,18 +1343,16 @@ FOR i IN REVERSE 10..1 LOOP
END LOOP;
</programlisting>
</para>
</listitem>
</varlistentry>
</variablelist>
</sect3>
</sect2>
<sect3 id="plpgsql-records-iterating">
<title>Iterating Through Records</title>
<sect2 id="plpgsql-records-iterating">
<title>Looping Through Query Results</title>
<para>
Using a different type of FOR loop, you can iterate through
the results of a query and manipulate that data
accordingly. The syntax is as follows:
accordingly. The syntax is:
<synopsis>
<optional><<label>></optional>
FOR <replaceable>record | row</replaceable> IN <replaceable>select_query</replaceable> LOOP
...
...
@@ -1402,9 +1416,210 @@ END LOOP;
declared as a record/row variable. If not, it'spresumedtobe