is there a way of typing for if like:
var = (cond) ? true : false;
or do we have to use this format?
if (cond)
true
else
@Leonid Beschastny is correct about the inlining the if-else-end
statement, but If one must, then with any assignment value that can be evaluated as boolean, one can the shortcut boolean operators ||
and &&
:
(cond) && ((var=true_val)||1) || (var=false_val);
Rules:
||
and &&
must be used, NOT |
or &
(var=true_val)
must be followed by ||1
in case true_val == false
(var1=true_val)
while (var2=false_val)
)true_val
and false_val
can be different types provided each then can be evaluated as booleanAlternatively one can do this:
cond && (func1(..)||1) || func2(...);
provided func1
and func2
return a boolean testable value including nothing at all (but no cell arrays!):