Re: Is there limitation for switch case: argument's value?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Oh I see. I missed out one thing too.
There is no need to put the same code under both case 7 & 6 separately, but just under case 6 will do.
This is simpler in fact!
Thanks Tedd and Torben!
I'll fix to this style from now onwards.


"tedd" <tedd.sperling@xxxxxxxxx> wrote in message news:p06240800c6b84328c140@[192.168.1.100]...
At 9:44 PM -0700 8/22/09, Lars Torben Wilson wrote:
Hi Keith,

Glad it works! I'm not sure how inverting the case statement helps you
minimize the code in each case. As both I and Adam showed, you can do
the same thing more efficiently (and IMHO much more readably) like
this:

switch ($sum)
{
    case 8:

       break;
    case 7:
    case 6:
       break;
    case 2:
    case 1:
       break;
    case 0:
       break;
    default:
       break;
}


Additionally, I would argue there's nothing different below other than it's even more easier to read and understand:

switch ($sum)
   {
    case 0:
    break;

    case 1:
    case 2:
    break;

    case 6:
    case 7:
    break;

    case 8:
    break;

    default:
    break;
   }

Cheers,

tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux