On Wed, Jun 10, 2020 at 11:05 PM xiangdong...@gmail.com <xiangdong...@gmail.com> wrote: > > Wondering if the 'expression' part of an if-statement should be in one line > only, given the following case, 'go tool compile' will report a syntax error > > Enter code here... > package p > > func cf1() int { > return 0 > } > > func cf2() int { > return 10 > } > > func f() { > if cf2() - 1 > < cf1() { > println("tested") > } > } > > > ss.go:13:3: syntax error: unexpected <, expecting expression > > Guess there might be syntax specification rules but I failed to find out.
It's because of automatic semicolon insertion. You need to put the "<" at the end of the "if" line, not at the start of the next line. See https://golang.org/ref/spec#Semicolons . Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXJkjsa8tDOQYSrPp0PXWF-xvwj-gJFFJQk5LS9DjdxSw%40mail.gmail.com.