-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatements.go
114 lines (78 loc) · 1.55 KB
/
statements.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// the if statement
package main
import ("fmt")
func main(){
/*
if 20 > 18{
fmt.Println("20 is greater than 18")
}
*/
/*
x := 20
y := 18
if x > y{ // it gives unexpected newline error, if you put a newline next to the condition
fmt.Println("x is greater than y")
}
*/
// if- else
/*
time := 20
if (time < 18) {
fmt.Println("good day")
}else{ // here the else statement should follow the closing curly brackets, and we should not leave a newline after the if statements without a curly bracket
fmt.Println("good evening ")
}
*/
// if - else if
/*
*/
/*
time := 22
if time < 10{
fmt.Println("Good morning.")
} else if time < 20 {
fmt.Println("Good day")
} else {
fmt.Println("good evening.")
}
*/
/*
a := 14
b := 14
if a < b{
fmt.Println("a is less than b")
} else if a > b {
fmt.Println("a is greater than b")
} else {
fmt.Println("a and b are equal")
}
*/
/*
x := 30
if x >= 10{
fmt.Println("x is larger than or equal to 10") // if condition 1 and condition 2 are both true, only the code for condition1 are executed.
} else if x >20 {
fmt.Println("x is larger than 20")
} else {
fmt.Println("x is less than 10")
}
*/
/*
nested if statement
if condition1 {
// code to be executed if condition1 is true
if condition2 { // code to be executed if both condition1 and condition2 are true
}
}
}
*/
num := 20
if num >= 10 {
fmt.Println("Num is more than 10.")
if num > 15{
fmt.Println("Num is also more than 15.")
}
}else {
fmt.Println("Num is less than 10.")
}
}