labeling data - Maps - for...range loops
Head First Go、 Jay McGavren(著)、O’Reilly Media)の Chapter 7(labeling data - Maps)、p.226(Code Magnets)の解答を求めてみる。
コード
main.go
package main
import "fmt"
func main() {
ranks := map[string]int{"gold": 1, "silver": 2, "bronze": 3}
for medal, rank := range ranks {
fmt.Printf("The %s medal's rank is %d\n", medal, rank)
}
}
入出力結果(Terminal, Zsh)
% go run ./main.go
The gold medal's rank is 1
The silver medal's rank is 2
The bronze medal's rank is 3
%