The range keyword is used in for loop to iterate over items of an array, slice, channel or map. With array and slices, it returns the index of the item as integer. With maps, it returns the key of the next key-value pair. Range either returns one value or two. If only one value is used on the left of a range expression, it is the 1st value in the following table.
Range-Expression
1st value
2nd value(optional)
Array or slice a [n]E
index i int
a[i] E
String s string type
index i int
rune int
map m map[K]V
key k K
value m[k] V
channel c chan E
element e E
none
Example
Following is the example:
When the above code is compiled and executed, it produces the following result:
Related Searches to Golang Range | Range In Golang
golang range intgolang range slicegolang for range channelgolang range templategolang range mapgolang loop n timesgolang range stringgolang map of structsrange in golanggolang rangego for rangego rangefor range golangrange golanggolang for rangegolang html template rangegoing to the rangerange to gorange gogo articlesgolang mapgocodewhat is go languageinstall golanggo idegolang downloadinstall gogo installgo by examplegolanggoprogoogle gogolang tutorialgoogle languagego languagego programming languagego languagego programming languagegolang tutorialgo googlegoogle gogolanggp languagego programming language bookgolang coursethe go programming languagebest book to learn golanggolang web development tutorialgolang big datago language bookbig data golanggolang booklearn golanggolang programsgo programming language usesgo to google go to googlelearn go programminggoogle and gowhat is go programming languagego google go google go googlewhich programming language used in googlego to the bookgo scripting languagegolang online tutorialgoogle language programminggo language programminggolang iotgo to go to googlewhy go languagego programming language tutorialgo language tutoriallearn go languagegolang jobsgoogle go softwareprogramming language gogo programing languagegolang web frameworkgo for googlego language ide for windowsgoogle golanggolang programminggoogle coding languagegolang projectsgo programming tutorialgoogle go language tutorialgolang debuggergo to the googlegoogle go programming languagegolang classgolang serverprogramming language used by googlegoogle go languagego programminggo programming pdfgolang developmentgolang frameworkgo language examplesgolang tutorial pdflanguage googlego programgo programming language pdf