On 25/03/2025 02:06, Adriano dos Santos Fernandes wrote:
> # Range-based FOR statement (FB 6.0)
>
> ## Description
>
> The range-based `FOR` statement is used to iterate over a range of
> values. The iteration is performed in increasing
> order when used with `TO` clause and in decreasing order when used with
> `DOWNTO` clause.
>
> ## Syntax
>
> ```
> [<label> :]
> FOR <variable> = <initial value> {TO | DOWNTO} <final value> DO
> <statement>
> ```
Is this syntax inspired by another DBMS, if so, which one?
For example, PostgreSQL uses the following syntax:
```
[ <<label>> ]
FOR name IN [ REVERSE ] expression .. expression [ BY expression ] LOOP
statements
END LOOP [ label ];
```
(See
https://www.postgresql.org/docs/17/plpgsql-control-structures.html#PLPGSQL-INTEGER-FOR
)
In Firebird syntax, that would be something like:
```
[label:]
FOR varname IN [ REVERSE ] <expression> .. <expression> [ BY
<expression> ] DO
<compound_statement>
```
If you want only your proposed features (increment/decrement by 1):
```
[label:]
FOR varname IN [ REVERSE ] <expression> .. <expression> DO
<compound_statement>
```
To be clear, I'm fine with the original syntax, but using syntax similar
to another DBMS may have its advantages.
For comparison, Oracle PL/SQL uses:
```
FOR index IN lower_bound .. upper_bound
LOOP
statements;
END LOOP;
```
Which is similar to the PostgreSQL syntax.
(See also
https://docs.oracle.com/en/database/oracle/oracle-database/23/lnpls/FOR-LOOP-statement.html)
Mark
--
Mark Rotteveel