RE: if/elseif being treated as if/if

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

 



At 3:54 PM -0400 9/24/10, Bob McConnell wrote:
From: tedd

 At 2:23 PM -0400 9/24/10, Bob McConnell wrote:

 >>A switch works when a single test can dispatch all possible branches.
If
you have a series of tests where each looks for a different subset of
 >>conditions, you need an elseif.

 Not so, O'wise one.

 This will work:

 switch(1)
     {
     case $a > $b:
     /* whatever
     break;

     case $c == 1:
     /* whatever
     break;

     case $d == 'this works':
     /* whatever
     break;
     }

 Granted, it's not the normal way a switch works in some other
 languages, but it does work in PHP.  :-)

That is just so wrong, it can't actually be taken seriously. There is
simply no justification for such broken logic.

Bob McConnell

I take it seriously. In fact, I think it's a very good method of making several different comparisons in one control structure. For me, it is easy to understand, document, and maintain. Obviously, your mileage varies.

But besides the point, all I was showing was that your claim --

A switch works when a single test can dispatch all possible branches. If you have a series of tests where each looks for a different subset of conditions, you need an elseif.

-- was false. I don't need an elseif and never have. There has always been a way around using an elseif. The powers that be could boot that control and I would never miss it.

Cheers,

tedd
--
-------
http://sperling.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