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

From: Date: Tue, 25 Aug 2009 02:11:01 +0000
Subject: Re: Is there limitation for switch case: argument's value?
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-297160@lists.php.net to get a copy of this message
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@gmail.com> 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


« previous php.general (#297160) next »