if loop in go code example
Example 1: if statements in go
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...")
}
Example 2: go if
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))
}