Skip to content

Commit

Permalink
ok statement with map
Browse files Browse the repository at this point in the history
  • Loading branch information
0bvim committed Oct 11, 2024
1 parent 8c12b09 commit bac3d60
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/udemy/go_ted/section12/map_loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,24 @@ func main() {
for i, v := range m {
fmt.Printf("Name %v\tAge %v\n", i, v)
}

fmt.Println()

if age, ok := m["James"]; ok {
fmt.Println("The age is", age)
} else {
fmt.Println("Not match")
}

if age, ok := m["O"]; ok {
fmt.Println("The age is", age)
} else {
fmt.Println("Not match")
}

if age, ok := m["n"]; !ok {
fmt.Println("Not match")
} else {
fmt.Println("The age is", age)
}
}

0 comments on commit bac3d60

Please sign in to comment.