I recently came across a ternary logic statement in this form:
condition, condition ? condition ? expr1 : expr2 : expr3
I am not sure how to interpret this. I am not seeing anything on the web. Anybody got any info on this.
condition, condition ? condition ? expr1 : expr2 : expr3
First you have a comma operator. This evaluates as the right hand side. So the first condition does nothing.
condition ? condition ? expr1 : expr2 : expr3
Then you just have two ternary expressions
It is the same as:
condition ? (condition ? expr1 : expr2) : expr3
So if the first condition is false, you get expr3.
Otherwise, the second condition picks between expr1 and expr2.
Never write code like this! Concisenes is only a virtue to the point where it makes it hard to understand what code means.
if/else.