Skip to content

Commit bac3d60

Browse files
committed
ok statement with map
1 parent 8c12b09 commit bac3d60

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/udemy/go_ted/section12/map_loop.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,24 @@ func main() {
1414
for i, v := range m {
1515
fmt.Printf("Name %v\tAge %v\n", i, v)
1616
}
17+
18+
fmt.Println()
19+
20+
if age, ok := m["James"]; ok {
21+
fmt.Println("The age is", age)
22+
} else {
23+
fmt.Println("Not match")
24+
}
25+
26+
if age, ok := m["O"]; ok {
27+
fmt.Println("The age is", age)
28+
} else {
29+
fmt.Println("Not match")
30+
}
31+
32+
if age, ok := m["n"]; !ok {
33+
fmt.Println("Not match")
34+
} else {
35+
fmt.Println("The age is", age)
36+
}
1737
}

0 commit comments

Comments
 (0)