<p>Hey guys,</p>
<p>I was going through <a href="https://github.com/golang/tour/blob/master/solutions/loops.go" rel="nofollow">this solution</a>
from the Go Tour and saw this snippet of code:</p>
<pre><code>for math.Abs(n-z) > delta {
n, z = z, z-(z*z-x)/(2*z)
}
</code></pre>
<p>for loops are interesting in Go, and I've seen a few different ways to construct them,
but I don't see anywhere in the docs what it means to have parts of the body separated by commas
like that.</p>
<p>I tried stuff like the below just to replicate the previous structure:</p>
<pre><code>package main
import "fmt"
func main() {
x := 20
for i := 0; i < 10; i++ {
fmt.Println(i), fmt.Println(x)
}
}
</code></pre>
<p>but end up getting:</p>
<pre><code>.\reddit.go:8:33: syntax error: unexpected newline, expecting := or = or comma
</code></pre>
<p>Can someone give me a simple exam using the structure above?</p>
<hr/>**评论:**<br/><br/>nagai: <pre><p>It's just two assignments on one line, equivalent to</p>
<p><code>n = z
z = z-(z*z-x)/(2*z)
</code></p></pre>