I have two for loops with two different set of variables, where I also reuse one variable from one loop in the next. The code looks roughly like this:
func naive(z, x, y []uint32, n int) {
var i, j, k int
var A, B uint32
for i = 0; i < n; i++ {
B = 0
for j = 1; j <= i; j++ {
muladd(x[j], y[i - j], &A)
}
for k = 1; j < n; j++, k++ {
muladd(x[j], y[n - k], &B)
}
}
}
But I get an error message at the second for loop. It says missing { after for clause
. Any ideas how to solve it?
when you increment both j and k on the last loop go doesn't like it
so try to change your code to
func naive(z, x, y []uint32, n int) {
var i, j, k int
var A, B uint32
for i = 0; i < n; i++ {
B = 0
for j = 1; j <= i; j++ {
muladd(x[j], y[i-j], &A)
}
for k = 1; j < n; j++ {
muladd(x[j], y[n-k], &B)
k++
}
}
}
pay attention to the last loop I just moved the k++
statement inside the loop