Golang: Use one value in conditional from function returning multiple arguments

You cannot pick one of the multiple returned values but you can write something like

if square, _ := squareAndCube(n); square > m {
    // ...
}

The square variable will only be valid in the if scope. These “simple statements” can be used in if statements, switch statements and other constructs such as for loops.

See also the effective go article on if statements.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)