hugomg
hugomg

Reputation: 69924

Why are golang semicolons optional before a close parenthesis?

According to the Go documentation a semicolon is optional if it is just before a ) or }.

To allow complex statements to occupy a single line, a semicolon may be omitted before a closing ")" or "}".

I understand how the } rule allows one liners such as the following:

if x { return 1 }

But what is the purpose of the ) rule? What kind of statement or other semicolon thing can appear just before a close parenthesis?

Upvotes: 0

Views: 550

Answers (1)

user12258482
user12258482

Reputation:

To find where semicolons can appear before a closing parenthesis, search the specification for the text ";" } ")".

Examples:

import ( "fmt"; )
var ( v int; )
const ( c = 1; )
type ( t []int; )

Upvotes: 3

Related Questions