ReferenceVerse

Iterate An Array

iterate an array

Updated
Watch the Knot — iterate-an-array in ~90 seconds.

Three ancient pearls light up the Sunken Athenaeum, and your code needs to tally their power before the tide rolls in.

A for-loop acts like an underwater current, pulling each relic from your array one by one to process it.

We declare our array of scores, set a running total, then loop through each value, adding it to the pile.

Reach for a for-loop whenever you need to touch every item in a collection exactly once.

RelicScores : []int = array{100, 250, 500}
var TotalScore : int = 0
for (Score : RelicScores):
    set TotalScore = TotalScore + Score

Build your own lesson with iterate-an-array

Generate a personalized, compile-checked lesson grounded in this exact reference.

Build a lesson →