What is the advantage of commas in a conditional statement?

后端 未结 7 1896
醉酒成梦
醉酒成梦 2021-02-03 17:25

We can write an if statement as

if (a == 5, b == 6, ... , thisMustBeTrue)

and only the last condition should be satisfiable to ent

7条回答
  •  感情败类
    2021-02-03 17:44

    There is no advantage: the comma operator is simply an expression with type of the last expression in its expression list and an if statement evaluates a boolean expression.

    if() { ... }
     with type of  boolean
    

    It's a weird operator true, but there's no magic to it - except that it confuses lists of expressions with argument lists in function calls.

    foo()
     with  := [[, ]*]
    

    Note that in the argument list, comma binds stronger to separating arguments.

提交回复
热议问题