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
a := 4
b := 6
if a + b == 10 {
fmt.Println("a + b is equal to 10!")
} else {
fmt.Println("a + b does not equal 10...")
}
xxxxxxxxxx
func sqrt(x float64) string {
if x < 0 {
return sqrt(-x) + "i"
}
return fmt.Sprint(math.Sqrt(x))
}
func main() {
fmt.Println(sqrt(2), sqrt(-4))
}
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
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)
}
}
xxxxxxxxxx
if num := 9; num < 0 {
fmt.Println(num, "is negative")
} else if num < 10 {
fmt.Println(num, "has 1 digit")
} else {
fmt.Println(num, "has multiple digits")
}