Re: IF or SWITCH

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

 



On Wed, 2006-04-05 at 22:48, Ray Hauge wrote:
> Hello World! wait, not coding... (sorry, long night)
> 
> Okay, I finally finished hashing out all the logic for a very complex set of 
> rules to determine what "type" an application should be set to.  I won't bore 
> you with the details of it, but the question is...
> 
> I have 57 if/elseif/else statements because of all the different criteria.  Is 
> it considered better programming practice to use if/elseif/else statements 
> over a switch(true) case (true && false || true || false) syntax?
> 
> Basically, I'm not too happy with the readability of the code, but I'm afraid 
> that at this point there's not much I can do...
> 
> code snippet:
> 
> if($numFFELP > 1 && count($FFELP_Lenders) > 1 && $numFFELP == $numTotal){
> 	$retVal = array(TRUE, 'A');
> }elseif($numFFELP > 0 && $enumFFELP > 0 && count($FFELP_Lenders) > 1 && 
> $enumFFELP + $numFFELP == $numTotal){
> 	$retVal = array(TRUE, 'A');
> }elseif($numFFELP > 0 && $numCONS > 0 && count($FFELP_Lenders) > 1 && 
> $numFFELP + $numCONS == $numTotal){
> etc.

Well I'd use if/elseif/else but I don't format like you...

<?php
if( $numFFELP > 1
    &&
    count( $FFELP_Lenders ) > 1
    &&
    $numFFELP == $numTotal )
{
    $retVal = array( TRUE, 'A' );
}
else
if( $numFFELP > 0
    &&
    $enumFFELP > 0
    &&
    count( $FFELP_Lenders ) > 1
    &&
    ($enumFFELP + $numFFELP) == $numTotal )
{
    $retVal = array( TRUE, 'A' );
}
else
if( $numFFELP > 0
    &&
    $numCONS > 0
    &&
    count( $FFELP_Lenders ) > 1
    &&
    ($numFFELP + $numCONS) == $numTotal )
{
    // Wheeeeeeeeeeeeeeeeeeee!
}
?>

Yeah it's vertically sprawling, yeah it looks tedious to type, but damn
is it clear *lol*. Once you get into a habit it becomes second nature.

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

-- 
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