From cfa26f23fd4f65896f01df2997f64c5ca184f484 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Bohin Date: Mon, 4 Aug 2014 22:23:24 +0200 Subject: [go/en] add an example for range - fixes #351 --- go.html.markdown | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/go.html.markdown b/go.html.markdown index a1be08af..77961524 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -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 { -- cgit v1.2.3 From 26166afc65772f31b4f189124019d9df85bbbadf Mon Sep 17 00:00:00 2001 From: Jean-Christophe Bohin Date: Thu, 7 Aug 2014 22:43:59 +0200 Subject: Fixed style Didn't uppercased 'range' in the beginning of the sentence since it's a language keyword. --- go.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go.html.markdown b/go.html.markdown index 77961524..02ea280d 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -178,8 +178,8 @@ func learnFlowControl() { 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) + // 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) -- cgit v1.2.3