package main
import ("fmt")
func fibonacci() func(int) int {
pre_pre, pre := 1, 1;
return func(x int) int {
if x == 0 || x == 1 {
return pre
} else {
tmp := pre_pre + pre
//
//pre_pre = pre
//pre = tmp
//
//pre_pre, pre = pre, tmp
//
pre, pre_pre = tmp, pre
return tmp
}
}
}
func main() {
f := fibonacci()
for i := 0; i < 10; iPP {
fmt.Println(f(i))
}
}
I use iterations to output Fibonacci sequences, and I use three methods for the two leading numbers in the iterative series: the first in the
comments, and the most common. The second and third of the
comments use the multiple assignment features of go.
the key is that the second and third kinds can output the sequence correctly .
I wonder, what is the order in which this multiple assignment is performed? How does it correctly parse my assignment steps (that is, the steps in the first one)?