Indexing, slicing, and iteration
Choose a slice before looping
Take the first two values and skip the rest.
values = [5, 8, 13]
for value in values[0..2]:
print(value)
5
8
The loop sees the slice. The original still contains all three values.
Indexing
Array indices start at zero. A dictionary lookup uses a key, and a missing dictionary key returns 'null'.
Slicing
A range index selects a half-open part of a sequence. A regular collection slice is shallow.
Iteration
Use 'for item in values:' for values, or 'for key, value in values:' when you also need the index or key.
Ordinary array indexing accepts nonnegative integral numeric indices within the dense sequence. For array insertion via add(array, index, value) use a signed integer. A dictionary can use text, numbers, null, or references as keys, subject to Atom equality. NaN is rejected. Hybrid tables treat negative integers, fractional numbers and higher sparse positions as associative keys. Dense sequence slice syntax returns a shallow array. It excludes the associative part. Dictionary iteration follows insertion order. Removing and reinserting a key moves it to the end. Iterators visit the live collection. In particular, deleting a dense item may shift and skip the next item. Iterate over a copy or extracted keys when performing structural changes.