typeover
curriculum

Curriculum Collections Iteration with range exercise 6 · mcq

Iteration with range

Go 1.22 added a new range form that lets you iterate over an INTEGER directly — the modern, idiomatic count-up loop. Pick the Go form that iterates i from 0 through 9. TypeScript: ``ts for (let i = 0; i < 10; i++) { console.log(i); } ``

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.