Syntax for checking if an element exists in a list

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Feb 5 06:23:56 PST 2015


On Thursday, 5 February 2015 at 13:31:21 UTC, Nicholas Wilson 
wrote:
> Note that D does NOT have default fall through. i.e.
>  switch(myopt)
> {
>     case "opt1", "opt2", "opt3":
>         do_A();
>         break;
>     case "opt4":
>         do_B();
>         break;
>     default:
>         do_C();
>  }
> is equivalent to
> switch(myopt)
> {
>     case "opt1", "opt2", "opt3":
>         do_A();
>     case "opt4":
>         do_B();
>     default:
>         do_C();
>  }

No, that's not right.

The docs [1] say that "[a] ScopeStatementList must either be 
empty, or be ended with a ContinueStatement, BreakStatement, 
ReturnStatement, GotoStatement, ThrowStatement or assert(0) 
expression unless this is the last case."

That's different from what you said. `case "opt1": doA(); case 
"4": do_B();` is supposed to be forbidden. It's not supposed to 
have an implicit break.

And apparently, dmd is not there (yet?). Implicit fall-through is 
only a warning at the moment (which have to be switched on). It's 
not an error.

[1] http://dlang.org/statement.html#switch-statement


More information about the Digitalmars-d-learn mailing list