lua-users home
lua-l archive

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


Using do ... end can already be used to achieve something very similar to a switch statement, with fallthrough:
To take your example:
local flag = false
do
  if (i == 1) then
    flag = true
  end

end



On Fri, Aug 14, 2015 at 2:32 PM Coda Highland <chighland@gmail.com> wrote:
On Fri, Aug 14, 2015 at 11:29 AM,  <tobias@justdreams.de> wrote:
>
> Quoting "Soni L." <fakedme@gmail.com>:
>
>>
>> With orif:
>>
>> ```lua
>> local flag = false
>> if i == 1 then
>>     flag = true
>> orif i == 2 then -- explicit fallthrough
>>     print(flag)
>> else -- default
>>     print "Unknown!"
>> end
>> ```
>
>
> Lua has elseif which is I think exactly the same:
> local flag = false
> if i == 1 then
>     flag = true
> elseif i == 2 then -- explicit fallthrough
>     print(flag)
> else -- default
>     print "Unknown!"
> end
>
> Regards,
>   Tobias

No, elseif is totally different semantics, and elseif is exactly WHY I
think orif is a bad idea: elseif only fires if an earlier condition
wasn't true. orif looks syntactically like it ought to behave like
elseif, but it doesn't.

/s/ Adam