xxxxxxxxxx
if test_condition {
// run code if test_condition is true
} else {
// run code if test_condition is false
}
xxxxxxxxxx
package main
import "fmt"
func main() {
name := "Manager"
if name == "Manager" {
fmt.Println("This is the Manager")
} else {
fmt.Println("This is not the manager")
}
}
xxxxxxxxxx
if num < 0 {
fmt.Println(num, "is negative")
} else if num < 10 {
fmt.Println(num, "has 1 digit")
} else {
fmt.Println(num, "has multiple digits")
}
}
xxxxxxxxxx
package main
import "fmt"
func main() {
number := 10
// checks if number is greater than 0
if number > 0 {
fmt.Printf("%d is a positive number\n", number)
} else {
fmt.Printf("%d is a negative number\n", number)
}
}