|
|
||
|
On 14/08/15 04:08 PM, Jonathan Goble wrote:This can be written in stock Lua without any new features by using nested if blocks: local flag = false if i == 1 or i == 2 then if i == 1 then flag = true end print(flag) else print"Unknown!" endBut now you check for the condition twice.
This is easily re-written in DRY style:
local flag = i==1
if flag or i==2 then
print(flag)
else
print"Unknown!"
end
Still very clear and reduces the wordiness almost as much as the orif
proposal. Sometimes a good style is just as good as syntactic sugar.