map_days.go 588 B

123456789101112131415161718192021222324252627282930313233343536
  1. // map_days.go
  2. package main
  3. import (
  4. "fmt"
  5. )
  6. var Days = map[int]string{1: "monday",
  7. 2: "tuesday",
  8. 3: "wednesday",
  9. 4: "thursday",
  10. 5: "friday",
  11. 6: "saturday",
  12. 7: "sunday"}
  13. func main() {
  14. fmt.Println(Days)
  15. // fmt.Printf("%v", Days)
  16. flagHolliday := false
  17. for k, v := range Days {
  18. if v == "thursday" || v == "holliday" {
  19. fmt.Println(v, " is the ", k, "th day in the week")
  20. if v == "holliday" {
  21. flagHolliday = true
  22. }
  23. }
  24. }
  25. if !flagHolliday {
  26. fmt.Println("holliday is not a day!")
  27. }
  28. }
  29. /* Output:
  30. thursday is the 4 th day in the week
  31. holliday is not a day!
  32. */