concept range in category go

appears as: rge, range, rge
Get Programming with Go

This is an excerpt from Manning's book Get Programming with Go.

In Cascading Style Sheets (CSS), colors on screen are specified as a red, green, blue triplet, each with a range of 0–255. It’s the perfect situation to use the uint8 type, an 8-bit unsigned integer able to represent values from 0–255:

The range keyword provides an index and value for each element of an array with less code and less chance for mistakes, as shown in the next listing.

Listing 16.5. Iterating through an array with range: array-range.go
dwarfs := [5]string{"Ceres", "Pluto", "Haumea", "Makemake", "Eris"}

for i, dwarf := range dwarfs {
    fmt.Println(i, dwarf)
}
  • The range keyword can iterate over arrays.