summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNami-Doc <vendethiel@hotmail.fr>2014-08-08 10:49:26 +0200
committerNami-Doc <vendethiel@hotmail.fr>2014-08-08 10:49:26 +0200
commit26cfe0b94f523a0adb7bcb9fa8eb755e2d684a41 (patch)
tree2b33bf20fb672b228498f341f989639cfd227d56
parent5a42a4e3010b22ab5dd7507b0d8997a7b5eb123b (diff)
parent26166afc65772f31b4f189124019d9df85bbbadf (diff)
Merge pull request #700 from jcbohin/go-en-Range_clause-#351
[go/en] add an example for range - fixes #351
-rw-r--r--go.html.markdown8
1 files changed, 8 insertions, 0 deletions
diff --git a/go.html.markdown b/go.html.markdown
index a1be08af..02ea280d 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 {