How to do one-liner if else statement?

Can I write a simple if-else statement with variable assignment in go (golang) as I would do in php (for example):

$var = ( $a > $b )? $a: $b;

currently I have to use the following:

var c int
if a > b {
    c = a
} else {
    c = b
}

Sorry I can not remember the name if this control statement and I couldn’t find the info through in-site and google search. :confused:

1 Like

As the comments mentioned, Go doesn’t support ternary one liners. The shortest form I can think of is this:

var c int
if c = b; a > b {
    c = a
}

Refer: [Tutorial] Go by Example: If/Else