LEARN VOID / 06
Collections
Grow a list and work with its values.
Illustrative fragment — place this code inside a function. It is verified in an executable context, but the download is not a standalone program.
var scores: [i32] = []
scores.push(12)
scores.push(18)
scores.push(20)
var total = 0
for score in scores:
total += scoreCreate an empty typed list
This fragment belongs inside a function. [i32] declares a growable list of integers. The empty literal needs that type context. Three push calls add scores 12, 18 and 20; the order of calls is their order in the list.
Total the scores
The loop visits each score and adds it to total, which ends at 50. The fragment has no entry function and prints nothing. It can be followed by return total in an integer-returning function; that is how its result is verified.
Choose sharing or fixed storage
Assigning a growable list shares its identity, so mutations are visible through aliases. A fixed array includes its size, such as [i32, 3], and copies its value storage. Readonly views retain their restrictions through elements. See dictionaries for key/value data; do not assume a proposed pop API exists.