[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Switch/Case with Fallthrough
- From: Paige DePol <lual@...>
- Date: Wed, 20 Nov 2013 13:34:52 -0600
> On Nov 20, 2013, at 1:27 PM, Coda Highland <chighland@gmail.com> wrote:
>
>> On Wed, Nov 20, 2013 at 11:23 AM, 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?
>
> Nothing. Fallthroughs skip the case check.
>
> /s/ Adam
That, and the contents of the variable used for the switch statement is actually loaded into a local variable named "(switch)", which really is just loading a value from the constant pool. So, even if changing the variable could change the case matching it wouldn't as once switch has been passed the variable is no longer being used.
However, as Adam pointed out, once a single case matches the switch flow either exits at a break statement or fall through the switch blocks by jumping over any intervening case statements! :)
~pmd~