-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswitch.go
47 lines (37 loc) · 785 Bytes
/
switch.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
package main
import "fmt"
import "time"
func main(){
//simple switch
i:=5
switch i { //break not needed
case 1:
fmt.Println("one")
case 2:
fmt.Println("two")
default: //optional
fmt.Println("other")
}
//types of switch in GOLANG
//--Multiple Condition Switch--
switch time.Now().Weekday(){
case time.Saturday , time.Sunday:
fmt.Println("its weekend")
default:
fmt.Println("its work day")
}
//----TYPE SWITCH-----
whoAmI:=func(i interface{}){
switch t:= i.(type){ //switch i.(type) if dont wanna use t
case int:
fmt.Println("its an integer")
case string:
fmt.Println("its an string")
case bool:
fmt.Println("its boolean")
default:
fmt.Println("other",t)
}
}
whoAmI("golang") //output -its a string
}