How to complex switch?

Matthew Ong ongbp at yahoo.com
Thu May 12 05:21:25 PDT 2011


@dennis luehring

>just a question - did you thought about that longer then 1 minute?
>what real problem does this syntactic sugare solves?

I do not think that this is syntactic sugar. Compare this 2 block of code. Which
is easier to read? I am not asking the level to be at bash
shell script, (that would be great).
Hopefully you get the idea that I am trying to communicate here. switch compare to
if-else-chain is better to write and also avoided the
compilation error.

@KennyTM~:
:= sorry, it should not have been there. Typo error.

> switch(str){
>                     // regexp
> case "abc", "def", "as+b?": s1(); break;
>
> case "za+", "wd?", "aaa": s2(); break;
>
> default: s3();
> }
----------------------------------------------------------------------
if (match(str, regex("abc|def|as+b?")) {
   s1();
}else if (match(str, regex("za+|wd?|aaa")){ // a lot of () and | ... might have
missed out one of them
   s2();
}else{
   s3()
}


----------------------------------------------------------------------



More information about the Digitalmars-d mailing list