Var x int = (5 > 1)? 0 : 1?

Can I do:
func main() {
var x int = (5 > 1)? 0 : 1
fmt.Println(x)
}

./hello.go:6:23: syntax error: unexpected literal 0 at end of statement

Sorry, Golang does not support ternary operator
https://golang.org/doc/faq#Does_Go_have_a_ternary_form

3 Likes

FYI, when I was looking this up myself, this thread post had some useful alternatives for how to achieve ternary operator effect besides the official normal solution.

1 Like