How to complex switch?

Matthew Ong ongbp at yahoo.com
Thu May 12 05:58:48 PDT 2011


@dennis luehring

----------------------------------------------------------------------
if (match(str, regex("abc|def|as+b?") && BLUB || BLA ... )
{
     s1();
}else if (match(str, regex("za+|wd?|aaa")){
...
----------------------------------------------------------------------

switch(str){
                     // regexp
 case "abc", "def", "as+b?":
   if( str == xxxx || str == yyyy && etc...){ // some other condition...
      s1();
   }
   break;

 case "za+", "wd?", "aaa":
   s2();
   break;

 default: s3();
 }

Denise, please note that I did not say it could not be done with if-else chain,
but switch makes some logical writing easier and code generation processing easier.

Some of the valid reason:
1) Less key stroke
2) Easier code generator to implement ( switch case can be processed by awk like
script with marker like 'case' and 'break'.

Most of the time, by making the code easier for man to read it also makes
generations of code easier.


http://www.digitalmars.com/d/

D is a systems programming language. Its focus is on combining the power and high
performance of C and C++ with the programmer >productivity< of >modern< languages
like Ruby and Python. Special attention is given to the needs of quality
assurance, documentation, management, portability and reliability.






More information about the Digitalmars-d mailing list