| 1 |
name: range |
| 2 |
returns: range |
| 3 |
since: 0.58.0 |
| 4 |
description: | |
| 5 |
Return an opaque object that can be only be used in `foreach` statements. |
| 6 |
|
| 7 |
<pre><code class="language-meson">[[@range]] range([[@int]] <b>stop</b>) |
| 8 |
[[@range]] range([[@int]] <b>start</b>, [[@int]] <b>stop</b>[, [[@int]] <b>step</b>])</code></pre> |
| 9 |
|
| 10 |
- `start` must be integer greater or equal to 0. Defaults to 0. |
| 11 |
- `stop` must be integer greater or equal to `start`. |
| 12 |
- `step` must be integer greater or equal to 1. Defaults to 1. |
| 13 |
|
| 14 |
It cause the `foreach` loop to be called with the value from `start` included |
| 15 |
to `stop` excluded with an increment of `step` after each loop. |
| 16 |
|
| 17 |
example: | |
| 18 |
```meson |
| 19 |
# Loop 15 times with i from 0 to 14 included. |
| 20 |
foreach i : range(15) |
| 21 |
... |
| 22 |
endforeach |
| 23 |
``` |
| 24 |
|
| 25 |
The range object can also be assigned to a variable and indexed. |
| 26 |
```meson |
| 27 |
r = range(5, 10, 2) |
| 28 |
assert(r[2] == 9) |
| 29 |
``` |
| 30 |
|
| 31 |
optargs: |
| 32 |
start: |
| 33 |
type: int |
| 34 |
default: 0 |
| 35 |
description: The start of the range |
| 36 |
|
| 37 |
stop: |
| 38 |
type: int |
| 39 |
description: The end of the range |
| 40 |
|
| 41 |
step: |
| 42 |
type: int |
| 43 |
default: 1 |
| 44 |
description: The loop increment |