if, else if and else in Go
In this post, you will learn how to work with decisions (if, else if and else) so that you can use that same knowledge and thus evolve.
package main
import "fmt"
/*
(if - if) condition is true {
the code inside the if is executed
}
(else if - otherwise if) condition is true (else if only occurs if if condition is false) {
code inside else if is executed
}
(else - if not) no condition (only occurs if condition of if and else if are false) {
the code inside the else is executed
}
*/
func main() {
x := 30
if x == 10 {
fmt.Println("The value of x is equal to 10.")
} else if x == 20 {
fmt.Println("The value of x is equal to 20.")
} else {
fmt.Println("The value of x is different from 10 and 20.")
}
}
// The value of x is different from 10 and 20.
Don’t forget to watch the video and you can always read this post in Portuguese.