File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import "fmt"
4
+
5
+ func main () {
6
+ // Normal Switch
7
+
8
+ age := 20
9
+ job := "Programmer"
10
+
11
+ switch age {
12
+ case 20 :
13
+ fmt .Println ("Age is 20" )
14
+ fmt .Println ("Your job is" , job )
15
+ case 10 :
16
+ fmt .Println ("Age not met to have a job!" )
17
+ default :
18
+ fmt .Println ("Age is not met requirement!" )
19
+ }
20
+
21
+ // Switch with Short Statement
22
+
23
+ switch length := len (job ); length < 10 && age >= 20 {
24
+ case true :
25
+ fmt .Println ("Job length is short" )
26
+ case false :
27
+ fmt .Println ("Job length is normal" )
28
+ }
29
+
30
+ // Switch without Condition
31
+
32
+ switch {
33
+ case age > 10 && age <= 17 :
34
+ fmt .Println ("Please go to school!" )
35
+ case age >= 20 :
36
+ fmt .Println ("Please go to work!" )
37
+ default :
38
+ fmt .Println ("You are to young!" )
39
+ }
40
+ }
You can’t perform that action at this time.
0 commit comments