|
2 | 2 |
|
3 | 3 | ## Description |
4 | 4 |
|
5 | | -The range-based `FOR` statement is used to iterate over a range of numeric values. The iteration is performed in |
6 | | -increasing order when used with `TO` clause and in decreasing order when used with `DOWNTO` clause. |
| 5 | +The range-based `FOR` statement iterates over a range of numeric values. The iteration is performed in |
| 6 | +increasing order with the `TO` clause, or in decreasing order with the `DOWNTO` clause. |
7 | 7 |
|
8 | 8 | ## Syntax |
9 | 9 |
|
10 | 10 | ``` |
11 | 11 | [<label> :] |
12 | | -FOR <variable> = <initial value> {TO | DOWNTO} <final value> [BY <by value>] DO |
13 | | - <statement> |
| 12 | +FOR <variable> = <initial value> {TO | DOWNTO} <final value> [BY <step value>] DO |
| 13 | + <compound statement> |
14 | 14 | ``` |
15 | 15 |
|
16 | 16 | ## Notes |
17 | 17 |
|
18 | | -- If omitted, `<by value>` is `1`. |
| 18 | +- If omitted, `<step value>` is `1`. |
19 | 19 | - `<variable>` also accepts parameters. |
20 | | -- `<variable>`, `<initial value>`, `<final value>` and `<by value>` must be expressions of exact numeric types. |
21 | | -- `BREAK` or `LEAVE [<label>]` can be used to exit the loop. |
22 | | -- `CONTINUE [<label>]` can be used to restart the next loop iteration. |
23 | | -- `<variable>` can be assigned by user code inside the loop. |
| 20 | +- `<variable>`, `<initial value>`, `<final value>` and `<step value>` must be expressions of exact numeric types. |
| 21 | +- `BREAK` or `LEAVE [<label>]` exits the loop. |
| 22 | +- `CONTINUE [<label>]` skips the remainder of the loop body and starts the next iteration. |
| 23 | +- `<variable>` can be modified by the loop body. |
24 | 24 |
|
25 | 25 | ## Execution |
26 | 26 |
|
27 | | -- `<initial value>` is evaluated and assigned to `<variable>`. If it is `NULL`, the loop is not executed. |
28 | | -- `<final value>` is evaluated and assigned to a temporary variable. If it is `NULL`, the loop is not executed. |
29 | | -- `<by value>` (or its default `1` value) is evaluated and assigned to a temporary variable. |
30 | | - If it is `NULL`, the loop is not executed. If it is zero or negative, an error is raised. |
| 27 | +- `<initial value>` is evaluated and assigned to `<variable>`. If `NULL`, the loop exits immediately. |
| 28 | +- `<final value>` is evaluated and assigned to a temporary variable. If `NULL`, the loop exits immediately. |
| 29 | +- `<step value>` (or its default value `1`) is evaluated and assigned to a temporary variable. |
| 30 | + If `NULL`, the loop exits immediately. If zero or negative, an error is raised. |
31 | 31 | - Loop starts: |
32 | | - - If it is not the first iteration: |
33 | | - - If `<variable>` is `NULL`, the loop is exited. |
34 | | - - `<variable>` is incremented (`TO`) or decremented (`DOWNTO`) by the cached `<by value>`. |
| 32 | + - If not the first iteration: |
| 33 | + - If `<variable>` is `NULL`, the loop exits. |
| 34 | + - `<variable>` is incremented (`TO`) or decremented (`DOWNTO`) by the cached `<step value>`. |
35 | 35 | - `<variable>` is compared (less than or equal for `TO` or greater than or equal for `DOWNTO`) to the cached |
36 | | - `<final value>` and if it is out of range, the loop is exited. |
37 | | - - Loop continues to the next iteration. |
| 36 | + `<final value>` and if false, the loop exits. |
| 37 | + - The body (`<compund statement>`) of the loop is executed. |
| 38 | + - The loop continues to the next iteration. |
38 | 39 |
|
39 | 40 | ## Examples |
40 | 41 |
|
|
0 commit comments