mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 03:34:15 +08:00
update book code
This commit is contained in:
34
eBook/exercises/chapter_4/function_calls_function.go
Normal file → Executable file
34
eBook/exercises/chapter_4/function_calls_function.go
Normal file → Executable file
@@ -1,18 +1,18 @@
|
||||
package main
|
||||
|
||||
var a string // global scope
|
||||
|
||||
func main() {
|
||||
a = "G"
|
||||
print(a)
|
||||
f1()
|
||||
}
|
||||
func f1() {
|
||||
a := "O" // new local variable a, only scoped within f1() !
|
||||
print(a)
|
||||
f2()
|
||||
}
|
||||
func f2() {
|
||||
print(a) // global variable is taken
|
||||
}
|
||||
package main
|
||||
|
||||
var a string // global scope
|
||||
|
||||
func main() {
|
||||
a = "G"
|
||||
print(a)
|
||||
f1()
|
||||
}
|
||||
func f1() {
|
||||
a := "O" // new local variable a, only scoped within f1() !
|
||||
print(a)
|
||||
f2()
|
||||
}
|
||||
func f2() {
|
||||
print(a) // global variable is taken
|
||||
}
|
||||
// GOG
|
Reference in New Issue
Block a user