Short Declaration of Variables

The short declaration of variables uses the following syntax:


ShortVarDecl = IdentifierList := ExpressionList
                        

Unlike regular variable declarations, a short variable declaration can redeclare variables as long as they were originally declared in the same block (or the parameter lists if the block is the function body) with the same type. and at least one of the non-blank variables is new. As a consequence, the redeclaration can only appear in a short multivariable declaration. Redeclaration does not introduce a new variable; it just assigns a new value to the original.

Short variable declarations can only appear inside functions. In some contexts, such as the "if", "for", or "switch" initializers, they can be used to declare temporary local variables.

short_variable_declaration.go