Skip to content
ChartDeck ChartScript docs Account Open the terminal

CS2702

error A loop over the items of a list needs an array.

#What it means

for (const x of ...) walks the elements of an array (or, with const [key, value], a map). The value after of is not a collection.

#Typical cause

  • A number after of, as in for (const i of 10).
  • A matrix: walk it with matrix.row or an index loop instead.

#How to fix it

To count, use for (let i = 0; i < 10; i++). To walk an array, put the array after of. See Loops.

#Example

ChartScriptError: CS2702
//@chartscript 1
indicator("Count")
let total = 0
for (const i of 10) {
    total += 1
}
plot(total)

Fixed

ChartScriptOpen in editor
//@chartscript 1
indicator("Count")
let total = 0
for (let i = 0; i <= 9; i++) {
    total += 1
}
plot(total)
  • CS2703 — word can only be used inside a loop.

The ChartScript documentation is in English for now; translations will follow.