I have the solution regarding execution order, but I cant understand how right associativity is linked to SCENARIO 2.
a ? b: c ? d : e ? f : g ? h : i // scenario 1 : associativity understood, which is : (a?b:(c?d:(e?f:(g?h:i))))
and
a ? b ? c : d : e // scenario 2 : NOT UNDERSTOOD
From the first answer here, I am able to understand the first scenario but not the second.
The obvious (and generally best) advice about things like this is "just don't do it."
Other than that, I find the easiest approach to be to think of them like Algol-style
ifs. An Algolifwas an expression, not a statement, so (much like a conditional, except readable) you could write something like this:The transformation is really pretty simple.
x ?isif (x)and:iselse. Applying this to a nested conditional is actually pretty easy, and at least in my opinion, the result is much more readable.Transforms to:
The second is actually just about as easy, as long as you remember that
x ?translates directly toif (x). Other than that, we follow the normal C rule that anelsematches up with the most recentifthat doesn't already have anelseassociated with it....becomes: