tags:

views:

246

answers:

2

Here is a test Go program:

package main
import fmt "fmt"
func main () {
    ex := "moo cow\n";
    fmt.Print (ex)
}

With the semicolon, it compiles. However, if the semicolon is removed, it doesn't:

string.go:5: syntax error near fmt

Any ideas?

+1  A: 

Well, the answer's technically here: http://golang.org/doc/effective_go.html#semicolons, but it's not very clear. It looks like you can leave semicolons off the end of statements, but not expressions. I think (I'm not certain here) that expressions are anything with an "=" (or ":=") in them (although += seems to be fine in the tutorial?)

Daniel G
After reading that, it sounds like you use them to separate statements in blocks, the way you do in Pascal. Outside of blocks, you don't need them.
Nosredna
+9  A: 

From The Go Programming Language Specification:

Elements of a list of statements are separated by semicolons, which may be omitted only if the previous statement:

  • ends with the closing parenthesis ")" of a list of declarations; or
  • ends with a closing brace "}" that is not part of an expression.
Laurence Gonsalves
...pretty ugly?
ZJR