Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Iterate over elements of map

package main

import "fmt"

func main() {
	grades := make(map[string]int)
	grades["Mary"] = 99
	grades["Jane"] = 88
	grades["Bob"] = 93

	for key, value := range grades {
		fmt.Printf("%-4s  %d\n", key, value)
	}
}
Mary  99
Jane  88
Bob   93