開発環境
- macOS Mojave - Apple (OS)
- Emacs (Text Editor)
- Windows 10 Pro (OS)
- Visual Studio Code (Text Editor)
- Go (プログラミング言語)
Head First Go (Jay McGavren(著)、O'Reilly Media)のChapter 2(which code runs next? - Conditionals and Loops)、Exercise(53)の解答を求めてみる。
コード
package main
import (
"fmt"
)
var a = "a"
func main() {
a = "a"
b := "b"
if true {
c := "c"
if true {
d := "d"
fmt.Println(a)
fmt.Println(b)
fmt.Println(c)
fmt.Println(d)
}
fmt.Println(a)
fmt.Println(b)
fmt.Println(c)
// fmt.Println(d) out of scope.
}
fmt.Println(a)
fmt.Println(b)
// fmt.Println(c) out of scope.
// fmt.Println(d) out of scope.
}
入出力結果(Bash、cmd(コマンドプロンプト)、Terminal)
$ go run sample2.go a b c d a b c a b $
0 コメント:
コメントを投稿