-
Notifications
You must be signed in to change notification settings - Fork 34
/
if-elseif-else.go
47 lines (41 loc) · 1023 Bytes
/
if-elseif-else.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
package main
import "fmt"
/*
* if-elseif-else program demonstrates the conditional statements in the
* Go programming language. In this program evenOdd function will explain
* if else block and signToWord program demonstrates if-elseif-else block
*/
func main() {
// It will demonstrate if-else statements
evenOdd()
// It will demonstrate if-elseif-else statements
signToWord()
//Special case when accessing a key from Map
//which is not present in Map
alphabets := make(map[string]string)
alphabets["A"] = "Apple"
if value, isSuccessful := alphabets["A"]; isSuccessful {
fmt.Println(value)
}
}
func evenOdd() {
for n := 1; n <= 10; n++ {
if n%2 == 0 {
fmt.Printf("Number %d is Even", n)
} else {
fmt.Printf("Number %d is Odd", n)
}
fmt.Println()
}
}
func signToWord() {
var sign string = "="
if sign == "=" {
fmt.Printf("Sign %s is equal to", sign)
} else if sign == "<" {
fmt.Printf("Sign %s is less than", sign)
} else {
fmt.Printf("Not a valid sign")
}
fmt.Println()
}