9951 explained code solutions for 126 technologies

golangHow to use range with map

package main

func main() {
  mp := map[string]string{"joe": "president", "donald": "not"}

  for k, v := range mp {
    print(k, ":", v, ";")
}ctrl + c
package main

default package declaration

func main() {

declare main function that will be launched automatically


creates new map

for k, v := range mp

iterate over mp map having keys/values in k and v respectively