-
Notifications
You must be signed in to change notification settings - Fork 0
/
switch1.go
58 lines (51 loc) · 939 Bytes
/
switch1.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
package main
import "fmt"
func main() {
// 예제 1
a := -7
switch {
case a < 0:
fmt.Println(a, "는 음수")
case a == 0:
fmt.Println(a, "는 0")
case a > 0:
fmt.Println(a, "는 양수")
}
// 예제 2
switch b := 27; {
case b < 0:
fmt.Println(b, "는 음수")
case b == 0:
fmt.Println(b, "는 0")
case b > 0:
fmt.Println(b, "는 양수")
}
// 예제 3
// 같은걸 찾아준다. Expression
switch c := "go"; c {
case "go":
fmt.Println("GO")
case "java":
fmt.Println("java")
default:
fmt.Println("일치하는 값 없음")
}
// 예제 4
switch c := "go"; c + "lang" {
case "golang":
fmt.Println("golang!")
case "java":
fmt.Println("java!")
default:
fmt.Println("일치하는 값 없음")
}
// 예제 5
switch i, j := 20, 30; {
case i < j:
fmt.Println("i는 j보다 작다")
case i == j:
fmt.Println("i와 j는 같다")
case i > j:
fmt.Println("i는 j보다 크다")
}
}