Is there a ternary operator in Go?
Is there a ternary operator in Go?
7
Author: Nicolas Chabanovsky, 2010-10-13
2 answers
There is no ternary operator in go. Use the conditional operator instead. That is, instead of
result = check ? true : false;
You need to write
if check {
result = true
} else {
result = false
}
9
Author: stanislav, 2010-10-13 16:37:55
As an option, shorten so
result = false
if check {
result = true
}
0
Author: Mark Irkzher, 2020-06-27 11:53:14