-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
52 lines (43 loc) · 955 Bytes
/
main.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
package main
import "fmt"
func main() {
// Example using if-else if-else
score := 85
if score >= 90 {
fmt.Println("You got an A!")
} else if score >= 80 {
fmt.Println("You got a B.")
} else if score >= 70 {
fmt.Println("You got a C.")
} else {
fmt.Println("You need to improve.")
}
// Example using switch
day := "Tuesday"
switch day {
case "Monday":
fmt.Println("It's the start of the week.")
case "Tuesday":
fmt.Println("It's not Monday anymore!")
case "Friday", "Saturday", "Sunday":
fmt.Println("It's the weekend!")
default:
fmt.Println("It's a regular weekday.")
}
// Example using switch with no expression
age := 25
switch {
case age < 18:
fmt.Println("You're a minor.")
case age >= 18 && age < 60:
fmt.Println("You're an adult.")
default:
fmt.Println("You're a senior citizen.")
}
}
/*
$ go run tutorial/conditional\ statements/main.go
You got a B.
It's not Monday anymore!
You're an adult.
*/