-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconditionals.go
73 lines (62 loc) · 1.08 KB
/
conditionals.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
66
67
68
69
70
71
72
73
package workshop
import (
"math"
"strconv"
"strings"
)
func conditionals() {
var str string
flag := true
if flag {
str = "Righteous Path"
}
assert(str == "Righteous Path")
var value int
if value < 10 {
value = 10
}
assert(value == 10)
value2 := 7
if value2 > 10 {
value2++
} else {
value2--
}
assert(value2 == 6)
const movie = "Rocky"
var score int
if movie == "Rambo" {
score = 9
} else if movie == "Rocky" {
score = 10
} else {
score = 6
}
assert(score == 10)
const food = "Pizza"
var drink string
switch food {
case "Fries":
drink = "Coke"
case "Sandwich":
drink = "Sprite"
default:
drink = "Milkshake"
}
assert(drink == "Milkshake")
rem := math.Mod(6, 5) == 1
assert(rem == true)
num := "5"
otherNum, err := strconv.Atoi(num)
if err == nil {
otherNum--
}
assert(otherNum == 4)
strVal := "The Knowledge"
// conditional can do an assignment and then have conditional
// strings.Contains returns a boolean
if ok := strings.Contains(strVal, "Knowledge"); ok {
strVal += " is there"
}
assert(strVal == "The Knowledge is there")
}