-
Notifications
You must be signed in to change notification settings - Fork 2
/
if-else.go
21 lines (19 loc) · 850 Bytes
/
if-else.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package main
import "fmt"
func main() {
code := 2
// an "if" statement, it has a condition followed by a block. if the condition evaluates to true then it run block conditions.
// an "if" statement is false then it will move to next "else if" or "else" condition if not present then it exit from block.
// condition checked followed by top down.
// the first one condition is true then it will not execute other blocks, even if their conditions also pass/true.
if code <= 5 {
fmt.Println("This is less then or equal to 5")
} else if code == 10 {
fmt.Println("This is more then value of code")
} else if code > 5 {
fmt.Println("This is greather then 5")
} else { //We have to write else statement after ending of }.
fmt.Println("Try again for success")
}
fmt.Println("Value of code will print here ",code)
}