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 infor (const i of 10). - A matrix: walk it with
matrix.rowor 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
//@chartscript 1
indicator("Count")
let total = 0
for (const i of 10) {
total += 1
}
plot(total)Fixed
//@chartscript 1
indicator("Count")
let total = 0
for (let i = 0; i <= 9; i++) {
total += 1
}
plot(total)#Related
- CS2703 — word can only be used inside a loop.