Sep 23, 2013 · In Go we use the keyword range within a for loop construct to iterate over a slice. In the beginning I made some very bad mistakes iterating over slices because I misunderstood how the range keyword worked. I will show you a nasty bug I created iterating over a slice that puzzled me for a bit. In Golang, range keyword is used in conjunction with for loop to iterate over the items of a collection. Range can be used with an array, string, map or channels. During each iteration, range can return one or two values based on the type of collection you are iterating. Following table, provides an overview of what range returns during iteration.
Mar 20, 2018 · A map is an unordered collection of key-value pairs. It maps keys to values. The keys are unique within a map while the values may not be. The map data structure is used for fast lookups, retrieval, and deletion of data based on keys. It is one of the most used data structures in computer science.