[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: orif
- From: Mason Bogue <scythe+lua@...>
- Date: Mon, 17 Aug 2015 11:21:44 -0700
>>local flag = false
>>if i == 1 or i == 2 then
>> if i == 1 then
>> flag = true
>> end
>> print(flag)
>>else
>> print"Unknown!"
>>end
>
>But now you check for the condition twice.
Just do this:
if i == 2 then
goto label
elseif i == 1 then
code()
label:
more_code()
end
The above pattern can be easily extended to handle an arbitrary number
of cases. Fallthrough can be nice but it's so rarely useful it's hard
to justify adding a new language feature to handle it when the "same"
performance effects (but conditions are now checked in reverse) can be
achieved thusly with goto.