Re: switch, case, and how it sometimes lets you fallthrough

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"Benny Raymond" <benny@xxxxxxxxxxxxxxx> wrote in message
news:%23DuDVGq$FHA.2036@xxxxxxxxxxxxxxxxxxxxxxx
> I'm confused as to how fallthrough is limited in switch. For example the
> following works:
>
> string switch_test = "a";
> switch (switch_test)
> {
> case "a":
> case "b":
> case "c":
> doSomething(a);
> break;
> }
>
> but the following does not work:
> string switch_test = "a";
> switch (switch_test)
> {
> case "a":
> if (<some test>)
> break;
> case "b":
> case "c":
> doSomething(a);
> }

You have to think of a C# switch differently than a C or C++ swtich. In C,
a switch looks like:

switch (value)
{
label1:
statement-list-1
label2:
statement-list-2
...
}

Any statment list can be empty, and you have fallthrough.

In C#, it's

switch(value)
{
label1A:
label1B:
label1C:
...
statment-list-1;

label2A:
label2B:
label2C:
...
statment-list-2;
}

A list of labels has to have at least one member. There is no fallthrough
from one statement list to the next.


.



Relevant Pages

  • Re: Go ahead. Stop programming. This ensures you from any mistakes.
    ... with the added problem of fallthrough. ... As Bob http://www.bobcongdon.net/blog/2003/12/c-switch-statement.html points it out, C# designers should introduce a "safe" must-break-switch rather than "improving" the switch by disallowing fall-through and then adding the goto junk. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Go ahead. Stop programming. This ensures you from any mistakes.
    ... integer const to integer var or defining a not yet defined variable or ... fallthrough in switch statements in C. ... with the added problem of fallthrough. ... emulating the "fallthrough" by explicit goto after every statement? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Go ahead. Stop programming. This ensures you from any mistakes.
    ... fallthrough in switch statements in C. ... with the added problem of fallthrough. ... "improving" the switch by disallowing fall-through and then adding the goto ... given that I don't use it - but it seems odd to complain that the ...
    (microsoft.public.dotnet.languages.csharp)
  • FIND across multiple tables in FM 7.03
    ... How can I run a FIND acros multiple tables? ... The member ID#'s are the link ... Seems that when I switch tables to add a FIND request in another table, ... Prev by Date: ...
    (comp.databases.filemaker)
  • motor switch
    ... with that switch since everyone says the k member is differnt from the ... Prev by Date: ...
    (rec.autos.makers.ford.mustang)