lua-users home
lua-l archive

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


On Wed, Nov 20, 2013 at 2:23 PM, Ulrich Schmidt <u.sch.zw@gmx.de> wrote:
What happens if you assign a new value to <variable> inside a case block and dont use break? What value become checked in the next case test? the new assigned one or the local remembred one?

Am 20.11.2013 18:13, schrieb Paige DePol:

switch <variable>      -- variable must be global or local
   case <constant>      -- constant: nil, true, false, number or string
     <block>            -- standard Lua block, all statements valid
     [break]            -- optional break, if not present will fall through
   case <constant>      -- to the block of the next case statement
     <block>
     [break]            -- repeat as many cases as you need
   case <constant>      -- specifying a constant more than once will
     <block>            -- generate a syntax error at compile time
     [break]
   else                 -- optional else block if no case conditions matched
     <block>            -- if last statement in else is a break it will be
end                    -- optimised out and will not appear in the bytecode



I'm pretty sure the behaviour in C is that the value is checked only at the "switch" statement, so changing the variable's value in one of the cases won't affect evaluation of other cases. This does mean it can't translate directly to if/else.

--
Sent from my Game Boy.