Why do we need a semicolon?

Here is the Go test program:

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

With a semicolon, it compiles. However, if the semicolon is removed, this does not mean:

string.go: 5: syntax error near fmt

Any ideas?


Update (March 2012) . Newer releases of Go can compile both forms (with and without semicolons).

+5
source share
2 answers

From Go Programming Language Specification :

Operator list items separated by semicolons, which can be omitted only if the previous statement:

  • ends with a closing parenthesis ")" in the list of ads; or
  • ends with a closing bracket "}", which is not part of the expression.
+10

, : http://golang.org/doc/effective_go.html#semicolons, . , , . ( , ), - - "=" ( ": =" ) ( + =, , )

+1

All Articles