for i, j := 0, 10; i < j; i, j = i+1, j-1 {
fmt.Println("Hello, playground")
}
Now I will preface this by saying this code quickly becomes harder to read if you get too complex, so I would err on the side of caution when doing this.
If the update clause is too complex for using the multi-assignment solution that @joncalhoun and @lutzhorn proposed, consider adjusting the variables within the loop body instead.
The i, j = i+1, j-1 works, but i = i+1 is slightly different from i += 1 (evaluation count). (And one assignment, even if tuple-assignment, can not always be enough if the “continue” part of the loop.)
In assignment operations, both the left- and right-hand expression lists must contain exactly one single-valued expression
Probably this wanted to mean that assignments take the form either
ExpressionList “=” ExpressionList
either
Expression ( add_op | mul_op ) “=” Expression
So with add_op or mul_op, lists (elements with at least one comma) are not permitted.
And use goto…
continue would be a bit safer and nicer than goto.
Not sure if I understand what you are trying to say.
What I meant with “adjusting the variables within the loop” is, if the post part is going to get too complex, move it into the loop body instead. For example, taking your initial post operation, you can move it to the end of the loop body like so:
for <init>; <conditions>; {
... do something here ...
i++; j -= 10; z *= 3
}