Skip to content

Commit 845c14c

Browse files
committed
Lesson 10: Learn If Expression
1 parent ad8077f commit 845c14c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

10. If Expression/ifexpression.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
// IF
7+
// If is one of the keyword in conditional statement
8+
// if block will be executed when the condition is true
9+
10+
// ELSE
11+
// Else block will be executed when the condition are not met/false
12+
13+
// ELSE-IF
14+
// Else-if block will be executed when previous condition are false, and current if is true
15+
16+
currentDay := "Senin"
17+
18+
if currentDay == "Senin" {
19+
fmt.Println("Semangat Pejuang Senin!")
20+
} else if currentDay == "Selasa" {
21+
fmt.Println("Tetap Semangat walaupun Sekarang Hari Selasa!")
22+
} else {
23+
fmt.Println("Sekarang bukan Hari Senin maupun hari Selasa!")
24+
}
25+
26+
// If with Short Statement
27+
// in Go-Lang we can create if statement with short way
28+
29+
if count := len(currentDay); count > 5 {
30+
fmt.Println("Nama hari lebih dari 5 huruf!")
31+
} else {
32+
fmt.Println("Nama harinya singkat!")
33+
}
34+
}

0 commit comments

Comments
 (0)