This question already has an answer here:
- Multiple variables in for loop in Go 1 answer
- For loop of two variables in Go 2 answers
I'm writing a for-loop statement, and I need to initialize two local variables to represent the indexes of strings a and b passed to the addBinary function. However, it's not allowed to put 'ia--, ib--' at the third position of for-loop. Is there an elegant way to do this?
func addBinary(a string, b string) string {
for ia, ib := len(a)-1, len(b)-1; ia >= 0 && ib >= 0; ia--, ib-- {
// some code
}
}
</div>