typeover
curriculum

Curriculum Collections Iteration with range exercise 2 · mcq

Iteration with range

Translate for (const n of nums) (value-only, no index) to Go. The trap: there's no for v := range slice form — that gives you the INDEX, not the value. You have to skip the index explicitly with the blank identifier _.

TypeScript reference
Pick the idiomatic Go translation

About this theme

for i, v := range collection is the workhorse. Over a slice you get (index, value). Over a map you get (key, value). Over a string you get (byteIndex, rune). Over a channel you get just the value, with no index. Use _ to discard either side.