Straight (non-procedural) SQL can perform simple For and For-Each loops. I didn't believe it myself, but reading Parsing CSV Values Into Multiple Rows showed me it could be done.
The trick lies in joining the table(s) of interest with a field whose values are the topic of the loop ($_ in Perl). If the field values are an unbroken simple sequence of numbers, you have a For loop. All other sets of topic values would be used in For-Each loops.
A simple example: Your local police have only 2 names for unknown perpetrators in their database, John Doe and Jane Doe, but needs 20 more names like John Doe #7 and Jane Doe #4. Using a field with values 1-10 as the loop topic ($_), you can create these additional names with SQL like:
(p.Name & ' #' & i.index) as Name
perpetrators p, indexes i
or p.Name="Jane Doe";
Since this is a cross join (no fields are joined between the two tables), the rows returned by the SELECT will be the Cartesian product of the two sets of values:
1 John Doe
2 John Doe
10 John Doe
1 Jane Doe
2 Jane Doe
10 Jane Doe
As you can see from this example, it is easy to derive the new perpetrator names from this SELECT using the Perpetrators.Name and Indexes.Index fields.
Why you would want to do this in SQL, I don't know. It reminds me of XSLTunit, somehow... But it does show how SQL can be used for simple For and For-Each loops.