Skip to content

Commit

Permalink
[go/en] add an example for range - fixes adambard#351
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbohin committed Aug 4, 2014
1 parent a0af5e9 commit cfa26f2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions go.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ func learnFlowControl() {
break // Just kidding.
continue // Unreached.
}

// you can use range to iterate over an array, a slice, a string, a map, or a channel.
// range returns one (channel) or two values (array, slice, string and map)
for key, value := range map[string]int{"one": 1, "two": 2, "three": 3} {
// for each pair in the map, print key and value
fmt.Printf("key=%s, value=%d\n", key, value)
}

// As with for, := in an if statement means to declare and assign
// y first, then test y > x.
if y := expensiveComputation(); y > x {
Expand Down

0 comments on commit cfa26f2

Please sign in to comment.