The range keyword in Go iterates over collections like slices and maps, returning the index/key and value for each element.
The range keyword in Go iterates over elements in arrays, slices, maps, strings, or channels, providing the index (or key) and value for each iteration.
numbers := []int{10, 20, 30}
for i, v := range numbers {
fmt.Printf("Index: %d, Value: %d\n", i, v)
}
For maps, range yields the key and value; for strings, it yields the byte index and the Unicode code point.
The range keyword is a loop tool that automatically walks through a list, map, or string item by item. It saves you from manually tracking the current position or counting items, acting like a conveyor belt that hands you each item one at a time. You use it whenever you need to process every element in a collection without writing complex loop logic.