Below
syntax print index and value of array elements.
for index,
value := range countries {
fmt.Println("index : ",
index, ", Value : ", value)
}
HelloWorld.go
package main import "fmt" func main() { countries := [4]string{"India", "Bangladesh", "Sri Lanka", "Japan"} for index, value := range countries { fmt.Println("index : ", index, ", Value : ", value) } }
Output
index : 0 , Value : India index : 1 , Value : Bangladesh index : 2 , Value : Sri Lanka index : 3 , Value : Japan
No comments:
Post a Comment