以下摘自The Go Programming Language:
The increment statement i++ adds 1 to i ; it’s equivalent to i += 1 which is in turn equivalent to i = i + 1 . There’s a corresponding decrement statement i– that subtracts 1. These are statements, not expressions as the y are in most languages in the C family, so j = i++ is illegal, and the y are postfix only, so –i is not legal either.
要注意,i++
和i--
在Go
语言中是语句,不是表达式,因此不能赋值给另外的变量。此外没有++i
和--i
。