forked from ArchitectingSoftware/CNSE-Class-Demo-Files
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconditionals.go
More file actions
61 lines (54 loc) · 1.06 KB
/
Copy pathconditionals.go
File metadata and controls
61 lines (54 loc) · 1.06 KB
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
package main
import "fmt"
func basicConditionalIf() {
//Go has basic conditionals
var x int = 10
if x > 5 {
println("x is greater than 5")
} else {
println("x is less than or equal to 5")
}
}
func basicConditionalSwitch() {
//Go also has switch statements
x := 10
switch x {
case 1:
println("x is 1")
case 2:
println("x is 2")
case 3:
println("x is 3")
default:
println("x is not 1, 2, or 3")
}
//note, unlike C the go switch can work on different types
//this is a string switch
y := "hello"
switch y {
case "hello":
println("y is hello")
case "goodbye":
println("y is goodbye")
default:
println("y is something else")
}
//GO can also switch on types
//this is a type switch
var z interface{}
z = 1
switch z.(type) {
case int:
println("z is an int")
case string:
println("z is a string")
default:
println("z is something else")
}
}
func RunConditionalDemo() {
fmt.Println("------ Running Conditional Demo ------")
basicConditionalIf()
basicConditionalSwitch()
fmt.Printf("-----------------------------------\n\n")
}