Skip to content

Commit 1de2a6b

Browse files
committed
mention how to create a decreasing sequence for indexing
1 parent c88aaaf commit 1de2a6b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/reference-manual/expressions.qmd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,13 @@ given in the following table.
804804
| all | `a[:]` | `a[1]`, ..., `a[N]` |
805805
| all | `a[]` | `a[1]`, ..., `a[N]` |
806806

807+
The range indexing with `:` allows only increasing sequences. Indexing
808+
with a decereasing sequence can be made by creating an integer array in
809+
the following way:
810+
```stan
811+
array[6] int ii = reverse(linspaced_int_array(6, 2, 7));
812+
```
813+
Then `a[ii]` evaluates to `a[7]`, ..., `a[2]`.
807814

808815
### Multiple index semantics {-}
809816

0 commit comments

Comments
 (0)