It may optionally give the variable an initial value; in some forms of
declaration the type of the initial value defines the type of the variable.
- VarDecl = "var" ( VarSpec | "(" VarSpecList [ ";" ] ")" ) | SimpleVarDecl .
+ VarDecl = "var" ( VarSpec | "(" VarSpecList [ ";" ] ")" ) .
VarSpec = IdentifierList ( Type [ "=" ExpressionList ] | "=" ExpressionList ) .
VarSpecList = VarSpec { ";" VarSpec } .
Block | IfStat | SwitchStat | ForStat | RangeStat .
UnstructuredStat =
- Declaration |
+ Declaration | SimpleVarDecl |
SimpleStat | GoStat | ReturnStat | BreakStat | ContinueStat | GotoStat .
SimpleStat =
There are two ways to return values from a function. The first is to
explicitly list the return value or values in the return statement:
- func simple_f () int {
+ func simple_f() int {
return 2;
}
condition need not be parenthesized and the "then" statement
must be in brace brackets.
- IfStat = "if" [ SimpleVarDecl ";" ] Expression Block [ "else" Statement ] .
+ IfStat = "if" [ SimpleStat ";" ] Expression Block [ "else" Statement ] .
if x > 0 {
return true;
Switches provide multi-way execution.
- SwitchStat = "switch" [ SimpleVarDecl ";" ] [ "Expression ] "{" { CaseClause } "}" .
+ SwitchStat = "switch" [ [ SimpleStat ";" ] "Expression ] "{" { CaseClause } "}" .
CaseClause = CaseList StatementList [ ";" ] [ "fallthrough" [ ";" ] ] .
CaseList = Case { Case } .
Case = ( "case" ExpressionList | "default" ) ":" .