mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 01:55:35 +08:00
update book code
This commit is contained in:
35
eBook/exercises/chapter_8/map_days.go
Executable file
35
eBook/exercises/chapter_8/map_days.go
Executable file
@@ -0,0 +1,35 @@
|
||||
// map_days.go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var Days = map[int]string{1:"monday",
|
||||
2:"tuesday",
|
||||
3: "wednesday",
|
||||
4: "thursday",
|
||||
5: "friday",
|
||||
6: "saturday",
|
||||
7: "sunday"}
|
||||
|
||||
func main() {
|
||||
fmt.Println(Days)
|
||||
// fmt.Printf("%v", Days)
|
||||
flagHolliday := false
|
||||
for k, v := range Days {
|
||||
if v == "thursday" || v == "holliday" {
|
||||
fmt.Println(v, " is the ", k , "th day in the week")
|
||||
if v == "holliday" {
|
||||
flagHolliday = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if !flagHolliday {
|
||||
fmt.Println("holliday is not a day!")
|
||||
}
|
||||
}
|
||||
/* Output:
|
||||
thursday is the 4 th day in the week
|
||||
holliday is not a day!
|
||||
*/
|
Reference in New Issue
Block a user