www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Are the below statements equivalent?

reply Machine Code <jckj33 gmail.com> writes:
Give:

enum Foo { a, b, c, d, e }
Foo f = Foo.c;

Are the below statements equivalent?

switch(f) {
     case Foo.a:
     case Foo.b:
          doSomething();
     break;
    // ...
}

and:

(note the comma in the case)

switch(f) {
    case Foo.a, Foo.b: doSomething(); break;
    // ...
}

I found it in some source code, tested and it does work but is 
this the standard behavior?
Dec 26 2018
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Wednesday, 26 December 2018 at 17:33:13 UTC, Machine Code 
wrote:
 Are the below statements equivalent?
Yes, it is defined here: https://dlang.org/spec/statement.html#switch-statement
Dec 26 2018
parent Machine Code <jckj33 gmail.com> writes:
On Wednesday, 26 December 2018 at 18:03:44 UTC, Adam D. Ruppe 
wrote:
 On Wednesday, 26 December 2018 at 17:33:13 UTC, Machine Code 
 wrote:
 Are the below statements equivalent?
Yes, it is defined here: https://dlang.org/spec/statement.html#switch-statement
Thanks!
Dec 27 2018