Is there a shorted "if / then" syntax available in Lua (I'm using Corona SDK specifically), like in some other languages... In particular along the lines of:
res = (a == b) ? "It worked" : "It did NOT work"
To represent x = a ? b : c
, the lua-users wiki suggests:
A frequently used and highly recommend solution is to combine the
and
andor
binary operators in a way that closely approximates the ternary operator:x = a and b or c
To represent x = a ? b : c ? d : e
, the wiki further suggests:
x = a and b or c and d or e
WARNING: This technique may fail if b
or d
are ever nil
or false
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With