14 Iteration
Use for to visit each element without managing an index yourself.
norm
main() {
List<String> steps = ["read", "run", "change"]
for step, index : steps {
printLine("${index}: ${step}")
}
for step : steps {
printLine(step)
}
printLine("done")
}Expected output:
text
0: read
1: run
2: change
read
run
change
doneThe first binding receives the element; the optional second binding receives its zero-based index. The loop body runs once for each element, in collection order.
Try it: Remove the index binding and print only the steps.
Precise rules: Reference.