WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Go - Range


The range keyword is utilized in for loop to iterate over items of an array, slice, channel or map. With array and slices, it restores the list of the thing as whole number. With maps, it restores the essential thing of the following key-value pair.
Range expression 1st Value second Value(Optional)
Array or slice a [n]E index I int a[i] E
String s string kind index I int rune int
map m map[K]V key alright K fee m[k] V
channel c chan E element e E none

Example

The accompanying passage proposes how to utilize go
package critical 

import "fmt" 

func generally essential() 

/* make a slice */ 

numbers := []int0,1,2,3,4,5 

/* print the numbers */ 

for i:= assortment numbers 

fmt.Println("Slice item",i,"is",numbers[i]) 

/* make a map*/ 

countryCapitalMap := map[string] string "France":"Paris","USA":"Washington D.C.","India":"Delhi" 

/* print map the use of keys*/ 

for us of a := extend countryCapitalMap 

fmt.Println("Capital of",u . S . An .,"is",countryCapitalMap[country]) 

/* print map utilizing key-fee*/ 

for joined conditions of america,capital := go countryCapitalMap 

fmt.Println("Capital of",united states,"is",capital) 

At the point when the above code is incorporated and completed, it creates the consequent outcome
 

$move run main.Cross 

slice article zero will be zero 

slice thing 1 will be 1 

slice thing 2 will be 2 

slice thing 3 will be 3 

slice item four will be four 

slice item five is 5 

Capital of France is Paris 

Capital of USA is Washington D.C. 

Capital of India is Delhi 

Capital of France is Paris 

Capital of USA is Washington D.C. 

Capital of India is Delhi