Statements and expressions

Why is in Go design ++ and - ++ and -- are statements, not expressions?

Probably to be explicit. Assignment is not an expression in Go and results in a syntax error.


Go has no comma operator and ++ and – are statements not expressions. Thus if you want to run multiple variables in a for you should use parallel assignment (although that precludes ++ and --).

for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
    a[i], a[j] = a[j], a[i]


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.