diff --git a/examples/variables/variables.go b/examples/variables/variables.go index 8e0912f..5fa61d4 100644 --- a/examples/variables/variables.go +++ b/examples/variables/variables.go @@ -29,6 +29,7 @@ func main() { // The `:=` syntax is shorthand for declaring and // initializing a variable, e.g. for // `var f string = "apple"` in this case. + // This syntax is only available inside functions. f := "apple" fmt.Println(f) } diff --git a/examples/variables/variables.hash b/examples/variables/variables.hash index 040888b..2665b92 100644 --- a/examples/variables/variables.hash +++ b/examples/variables/variables.hash @@ -1,2 +1,2 @@ -736ce4018f275bb8d12e5232349bae93611506b2 -iYyAIilyBRf +9aeef52b289d7ad9b9ac79f129d4e49f956c60ef +N5rWndIliJW diff --git a/examples/variables/variables.sh b/examples/variables/variables.sh index eb3b20d..9c3e69e 100644 --- a/examples/variables/variables.sh +++ b/examples/variables/variables.sh @@ -3,10 +3,4 @@ initial 1 2 true 0 -apple - -# The shorthand `:=` initialization of variable can -# only be used inside any function. -# If used outside any function, it would generate -# `syntax error: non-declaration statement outside -# function body`. +apple \ No newline at end of file diff --git a/public/variables b/public/variables index 7bf1c69..11c6fee 100644 --- a/public/variables +++ b/public/variables @@ -43,7 +43,7 @@ calls.
package main
int
is 0
.
The :=
syntax is shorthand for declaring and
initializing a variable, e.g. for
-var f string = "apple"
in this case.
var f string = "apple"
in this case.
+This syntax is only available inside functions.
$ go run variables.go initial @@ -165,21 +166,6 @@ initializing a variable, e.g. for
The shorthand :=
initialization of variable can
-only be used inside any function.
-If used outside any function, it would generate
-syntax error: non-declaration statement outside
-function body
.