From 46f073bcc1e9ea045214d5082cf21d9fda6482c3 Mon Sep 17 00:00:00 2001 From: Seokchan Ahn Date: Wed, 25 Aug 2021 15:01:22 +0900 Subject: [PATCH] Fix indentation of goroutines on loop iterator variables example code --- CommonMistakes.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CommonMistakes.md b/CommonMistakes.md index 2d94b889..46b33af8 100644 --- a/CommonMistakes.md +++ b/CommonMistakes.md @@ -125,18 +125,18 @@ for _, val := range values { } func (v *val) MyMethod() { - fmt.Println(v) + fmt.Println(v) } ``` The above example also will print last element of values, the reason is same as closure. To fix the issue declare another variable inside the loop. ```go for _, val := range values { - newVal := val + newVal := val go newVal.MyMethod() } func (v *val) MyMethod() { - fmt.Println(v) + fmt.Println(v) } ```