開発環境
- macOS High Sierra - Apple
- Emacs (Text Editor)
- Go (プログラミング言語)
- Introducing Go: Build Reliable, Scalable Programs Caleb Doxsey (著) (参考書籍)
入門 Python 3 (Bill Lubanovic (著)、斎藤 康毅 (監修)、長尾 高弘 (翻訳)、オライリージャパン)の4章(Pyの皮: コード構造)、4.13(復習問題)4-1、2.をGoで取り組んでみる。
コード(Emacs)
package main
import "fmt"
func main() {
fmt.Println("1.")
guessMe := 7
if guessMe < 7 {
fmt.Println("too low")
} else if guessMe == 7 {
fmt.Println("just right")
} else {
fmt.Println("too high")
}
fmt.Println("2.")
for start := 1; ; start += 1 {
if start < guessMe {
fmt.Println("too low")
} else if start == guessMe {
fmt.Println("found it!")
} else {
fmt.Println("oops")
break
}
}
}
入出力結果(Terminal)
$ go run sample1.go 1. just right 2. too low too low too low too low too low too low found it! oops $
0 コメント:
コメントを投稿