-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.go
65 lines (55 loc) · 917 Bytes
/
hello.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import "fmt"
func main() {
a := 100
b := 11.3
c := "hoge"
var d bool
// データ型に応じたフォーマットを選択する
fmt.Printf("a: %d, b:%f, c:%s, d:%t\n", a, b, c, d)
// 定数はconst
const name = "takuma"
fmt.Println(name)
// iota = enum ?
const (
sun = iota // 0
mon
tue
)
fmt.Println(sun, mon, tue)
a1, b1 := 10, 100
if a1 > b1 {
fmt.Println("a > b")
} else if a1 < b1 {
fmt.Println("a < b")
} else {
fmt.Println("a = b")
}
for i := 0; i < 10; i++ {
fmt.Println(i)
}
// for {
// fmt.Println("無限ループ")
// }
n := 3
switch n {
case 3:
n = n - 1
fallthrough
case 2:
n = n - 1
fallthrough
case 1:
n = n - 1
fmt.Println(n) // 0
}
sumNum := sum(1, 2)
fmt.Println(sumNum)
fmt.Println(swap(1, 2))
}
func sum(i, j int) int { // == func sum(int i,int j)
return i + j
}
func swap(i, j int) (int, int) {
return j, i
}