以下Go代码运行正常:为什么在if条件中添加括号会导致编译错误?
package main
import "fmt"
func main() {
if j := 9; j > 0 {
fmt.Println(j)
}
}
但添加在条件括号后:
package main
import "fmt"
func main() {
if (j := 9; j > 0) {
fmt.Println(j)
}
}
有编译错误:
.\Hello.go:7: syntax error: unexpected :=, expecting)
.\Hello.go:11: syntax error: unexpected }
为什么编译器抱怨呢?
为什么C编译器会抱怨,如果你省略括号? – Volker