Raised This Month: $ Target: $400
 0% 

switch( ) sur deux cas


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Kidev
Veteran Member
Join Date: Jun 2010
Location: France
Old 11-23-2011 , 13:43   switch( ) sur deux cas
#1

Bonjour tout le monde!

Alors j'aimerai savoir un truc tout simple. Je switch() sur une case de tableau alors qu'il n'y a que deux cas possibles. Je trouve cela plus lisible. De plus, si je rajoute des options, cela sera plus rapide, et il n'y aura pour le coup plus à hésiter entre switch et if.

Qu'est-ce qui est le mieux? switch ou if() et else if() ?

Voici mon code qui lit un fichier de conf pour vous faire une idée:
PHP Code:
public iChatConfig( )
{
    new 
szCfgFile128 ];
    
get_configsdirszCfgFilecharsmaxszCfgFile ) );
    
formatexszCfgFilecharsmaxszCfgFile ), "%s/config.ichat"szCfgFile );

    new 
fp fopenszCfgFile"rt" );
    if ( !
fp )
    {
        return;
    }

    new 
szLineData364 ], szLineKey96 ], szLineValue264 ];
    while ( !
feoffp ) )
    {
        
fgetsfpszLineDatacharsmaxszLineData ) );
        
trimszLineData );

        if ( 
szLineData] == ';' || szLineData] == '#' || ( szLineData] == '/' && szLineData] == '/' ) || !szLineData] )
        {
            continue;
        }

        
parseszLineDataszLineKeycharsmaxszLineKey ), szLineValuecharsmaxszLineValue ) );

        switch ( 
szLineKey] )
        {
            case 
'F':
            {
                switch ( 
szLineKey] )
                {
                    case 
'D':
                    {
                        switch ( 
szLineKey11 ] )
                        {
                            case 
'A':
                            {
                                if ( 
equalszLineKey"FORMAT_DEF_ALIVE" ) )
                                {
                                    
copyformatAllDefAlivecharsmaxformatAllDefAlive ), szLineValue );
                                }
                            }
                            case 
'D':
                            {
                                if ( 
equalszLineKey"FORMAT_DEF_DEAD" ) )
                                {
                                    
copyformatAllDefAlivecharsmaxformatAllDefAlive ), szLineValue );
                                }
                            }
                        }
                    }
                    case 
'A':
                    {
                        switch ( 
szLineKey13 ] )
                        {
                            case 
'A':
                            {
                                if ( 
equalszLineKey"FORMAT_ADMIN_ALIVE" ) )
                                {
                                    
copyformatAllAdminAlivecharsmaxformatAllAdminAlive ), szLineValue );
                                }
                            }
                            case: 
'D':
                            {
                                if ( 
equalszLineKey"FORMAT_ADMIN_DEAD" ) )
                                {
                                    
copyformatAllAdminAlivecharsmaxformatAllAdminAlive ), szLineValue );
                                }
                            }
                        }
                    }
                    case 
'T':
                    {
                        switch ( 
szLineKey12 ] )
                        {
                            case 
'D':
                            {
                                switch ( 
szLineKey16 ] )
                                {
                                    case 
'A':
                                    {
                                        if ( 
equalszLineKey"FORMAT_TEAM_DEF_ALIVE" ) )
                                        {
                                            
copyformatTeamDefAlivecharsmaxformatTeamDefAlive ), szLineValue );
                                        }
                                    }
                                    case 
'D':
                                    {
                                        if ( 
equalszLineKey"FORMAT_TEAM_DEF_DEAD" ) )
                                        {
                                            
copyformatTeamDefAlivecharsmaxformatTeamDefAlive ), szLineValue );
                                        }
                                    }
                                }
                            }
                            case 
'A':
                            {
                                switch ( 
szLineKey18 ] )
                                {
                                    case 
'A'
                                    
{
                                        if ( 
equalszLineKey"FORMAT_TEAM_ADMIN_ALIVE" ) )
                                        {
                                            
copyformatTeamAdminAlivecharsmaxformatTeamAdminAlive ), szLineValue );
                                        }
                                    }
                                    case 
'D':
                                    {
                                        if ( 
equalszLineKey"FORMAT_TEAM_ADMIN_DEAD" ) )
                                        {
                                            
copyformatTeamAdminAlivecharsmaxformatTeamAdminAlive ), szLineValue );
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            case 
'C':
            {
                switch ( 
szLineKey] )
                {
                    case 
'C':
                    {
                        if ( 
equalszLineKey"CHAT_CLCMD_REMOVE" ) )
                        {
                            
removeOnSlash str_to_numszLineValue );
                        }
                    }
                    case 
'A':
                    {
                        if ( 
equalszLineKey"CHAT_ADMIN_SPY" ) )
                        {
                            
adminsSpy str_to_numszLineValue );
                        }
                    }
                    case 
'N':
                    {
                        if ( 
equalszLineKey"CHAT_NOTIFY" ) )
                        {
                            
userNotify str_to_numszLineValue );
                        }
                    }
                    case 
'R':
                    {
                        switch ( 
szLineKey12 ] )
                        {
                            case 
'A':
                            {
                                if ( 
equalszLineKey"CHAT_RADIUS_ALL" ) )
                                {
                                    
printRadiusAll str_to_floatszLineValue );
                                }
                            }
                            case 
'T':
                            {
                                if ( 
equalszLineKey"CHAT_RADIUS_TEAM" ) )
                                {
                                    
printRadiusTeam str_to_floatszLineValue );
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    
fclosefp );

Merci d'avance
__________________

Last edited by Kidev; 11-23-2011 at 13:47.
Kidev is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:13.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode