---
title: "Discussion on \"Common mistakes with for loops in Go\" | Hashnode"
description: "Discussion on \"Common mistakes with for loops in Go\". 先來一段程式\nfunc main() {\n    done := make(chan bool)\n\n    values := []string{\"a\", \"b\", \"c\"}\n    for _, v := range values {\n        /*\n        在每次loop中，此程式碼會啟動一個Goroutine來執行匿名函數。\n        該函數將當前的值v輸出出來，然後將true發送到done通道。\n        */\n        go func() {\n     ..."
url: "https://hashnode.com/posts/common-mistakes-with-for-loops-in-go/651da363879a835e13871f57"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Common mistakes with for loops in Go](https://blog.ganhua.wang/common-mistakes-with-for-loops-in-go?utm_source=hashnode&utm_medium=feed)

先來一段程式 func main() { done := make(chan bool) values := \[\]string{"a", "b", "c"} for \_, v := range values { /\* 在每次loop中，此程式碼會啟動一個Goroutine來執行匿名函數。 該函數將當前的值v輸出出來，然後將true發送到done通道。 \*/ go func() { ...

Oct 4, 2023 · 4 min read · blog.ganhua.wang  
Read the article

-   [#go](https://hashnode.com/tag/go)

## Written by

[雷N](https://hashnode.com/@nathanrayn)

@nathanrayn · Taipei, Taiwan

  
[View profile](https://hashnode.com/@nathanrayn)

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
