golang if statement or code example
Example 1: 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))
}
Example 2: golang if statement with string
import "strings"
// if string found in name it returns 0 else 1
if strings.Compare(name, "compare string") == 1 {
// Do something
}