Multiple assignment by if statement

前端 未结 2 1790
借酒劲吻你
借酒劲吻你 2021-02-06 09:30

It is possible to execute multiple assignment by if condition, like the following code?

func SendEmail(url, email string) (string, error) {

    genUri := buildU         


        
2条回答
  •  伪装坚强ぢ
    2021-02-06 10:24

    It looks like you want something like this:

    package main
    
    import "fmt"
    
    func a(int) int { return 7 }
    
    func b(int) int { return 42 }
    
    func main() {
        if x, y := a(1), b(2); x > 0 && x < y {
            fmt.Println("sometimes")
        }
        fmt.Println("always")
    }
    

    Output:

    sometimes
    always
    

提交回复
热议问题