<-- back

iff Keyword

The iff keyword is a new concept of NAL which has the following semantic:

Similar to a switch statement, the condition in round parantheses of a iff statement is compared to multiple values. In contrast to switch though, the values of an iff statement are evaluated on runtime (do not need to be constant values) and are executed as successing if and else if conditions whereas in each condition the given condition of the iff statement is compared to the given expression of the case with the equal operator.

Example:

NAL: iff(reaction.uiElement)(.gridSpacingUnitPt){ unit = KARO_LENGTH_UNIT_POINT; }else(.gridSpacingUnitmm){ unit = KARO_LENGTH_UNIT_MM; }else(.gridSpacingUnitMil){ unit = KARO_LENGTH_UNIT_MIL; }else{ unit = KARO_LENGTH_UNIT_POINT; } C: if(reaction.uiElement == con->gridSpacingUnitPt){ unit = KARO_LENGTH_UNIT_POINT; }else if(reaction.uiElement == con->gridSpacingUnitmm){ unit = KARO_LENGTH_UNIT_MM; }else if(reaction.uiElement == con->gridSpacingUnitMil){ unit = KARO_LENGTH_UNIT_MIL; }else{ unit = KARO_LENGTH_UNIT_POINT; }

There is no break instruction and there are no labels. Therefore, all code parts aside from the conditions in round parentheses behave like normal if statements. This also comprises the behaviour with or without curly brackets.

Further more, this construct could completely replace switch case. If there are constant expressions used, the compiler can automatically switch over to the traditional switch case. But as the fallthrough is still often used and a very practical use of switch case, it might be preferable to continue using it.

Discussion

One can think of a keyword fallthrough which (in C) automatically places a goto to the next else clause.

Maybe use when instead of iff. But when might be a varibale name.