Updated CommonMistakes (markdown)

Pete Vilter 2018-04-01 19:49:29 -04:00
parent 19ac262ac5
commit 1b5ef1700c

@ -27,7 +27,7 @@ for val := range values {
} }
``` ```
The ` val ` variable in the above loops is actually a single variable that takes on the value of each slice element. Because the closures are all only bound to that one variable, there is a very good chance that when you run this code you will see the last element printed for every iteration instead of each value in sequence, because the goroutines will probably not begin executing until after the loop. The above for loops might not do what you expect because their ` val ` variable is actually a single variable that takes on the value of each slice element. Because the closures are all only bound to that one variable, there is a very good chance that when you run this code you will see the last element printed for every iteration instead of each value in sequence, because the goroutines will probably not begin executing until after the loop.
The proper way to write that closure loop is: The proper way to write that closure loop is:
```go ```go