<p>I can't understand howcome only the loop part of total() function being run 3 times not the whole function. res := 0 runs only once while range part runs 3 times. My background is in Python and Java and the way total function is run not making sense at all. </p>
<p><a href="http://pastebin.com/4fEvfGsU" rel="nofollow">http://pastebin.com/4fEvfGsU</a></p>
<hr/>**评论:**<br/><br/>kl0nos: <pre><p>Because range on channel blocks if there is nothing to receive. You need to learn about channels in Go.</p></pre>hayzeus: <pre><p>Read up on channels and goprocs. You have started a background function (total()), which is going to read from channel <code>in</code>, adding to <code>res</code> until <code>in</code> is closed. Then the for loop end and the result is sent on the <code>out</code> channel back to <code>main</code></p>
<p><code>total</code> is NOT run three times. </p></pre>
