Friday, 3 May 2019

Go language: Print elements of array


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



Previous                                                 Next                                                 Home

No comments:

Post a Comment