lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Aug 17, 2015 at 11:21 AM, Mason Bogue <scythe+lua@ortsz.com> wrote:
>>>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.
>

The problem with goto is scope. Jumping between blocks is ugly ugly
messy. Even C puts restrictions on where you're allowed to goto into.
Unrestricted goto may not even be POSSIBLE in a modern programming
language.

/s/ Adam