If

Go’s if works just like you’d expect — with one difference from C-style languages: no parentheses around the condition. Braces {} are always required, though.

That’s it. No gotchas. Try it — run the example and pass a negative number to sqrt to see the imaginary result.

package main

import (
	"fmt"
	"math"
)

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))
}