From a45f939092cc2c60d49040bdb0147758a1403f61 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Sat, 6 Feb 2021 11:14:25 -0500 Subject: Add range() function Fixes: #5026. --- docs/markdown/snippets/range.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 docs/markdown/snippets/range.md (limited to 'docs/markdown/snippets') diff --git a/docs/markdown/snippets/range.md b/docs/markdown/snippets/range.md new file mode 100644 index 0000000..77635d6 --- /dev/null +++ b/docs/markdown/snippets/range.md @@ -0,0 +1,28 @@ +## New `range()` function + +``` meson + rangeobject range(stop) + rangeobject range(start, stop[, step]) +``` + +Return an opaque object that can be only be used in `foreach` statements. +- `start` must be integer greater or equal to 0. Defaults to 0. +- `stop` must be integer greater or equal to `start`. +- `step` must be integer greater or equal to 1. Defaults to 1. + +It cause the `foreach` loop to be called with the value from `start` included +to `stop` excluded with an increment of `step` after each loop. + +```meson +# Loop 15 times with i from 0 to 14 included. +foreach i : range(15) + ... +endforeach +``` + +The range object can also be assigned to a variable and indexed. +```meson +r = range(5, 10, 2) +assert(r[2] == 9) +``` + -- cgit v1.1