SA-MP Forums Archive
IF or SWITCH? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: IF or SWITCH? (/showthread.php?tid=395232)



IF or SWITCH? - Channeru - 25.11.2012

Hi everyone. I want to ask you what is better to use.

In callback OnPlayerSpawn i have random spawn function which detect position by Team

pawn Code:
if (Team == T_MEDIC)
    {
        SetPlayerPosEx(playerid, MedicPos[Pos][0], MedicPos[Pos][1], MedicPos[Pos][2], MedicPos[Pos][3]);
    }
    else if (Team == T_FARMER)
    {
    ....
should i use switch, or if ?
pawn Code:
switch(Team)
{
    case T_MEDIC: SetPlayerPosEx(playerid, MedicPos[Pos][0], MedicPos[Pos][1], MedicPos[Pos][2], MedicPos[Pos][3]);
    case T_FARMER: ....



Re: IF or SWITCH? - Nordic - 25.11.2012

how many cases do u have


Re: IF or SWITCH? - Konstantinos - 25.11.2012

I use switch only in large parts. If it's a part with 2 lines, if this, else I will use if/else statement.


Re: IF or SWITCH? - Crypt - 25.11.2012

Mostly "switch" is faster then "if/else" statements, but you can't use it everywhere.


Re: IF or SWITCH? - Channeru - 25.11.2012

Yes this is so large... so i'll use switch thank you