Go: Where is the ternary conditional operator?

Go has no ternary conditional operator. Instead of res = expr ? x : y you write:

if expr {
        res = x
} else {
        res = y
}

In some cases, you may create a dedicated function:

func Min(x, y int) int {
        if x <= y {
                return x
        }
        return y
}

Comments

Be the first to comment!