PDA

View Full Version : IF or SWITCH?


Channeru
25/11/2012, 03:59 PM
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


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 ?
switch(Team)
{
case T_MEDIC: SetPlayerPosEx(playerid, MedicPos[Pos][0], MedicPos[Pos][1], MedicPos[Pos][2], MedicPos[Pos][3]);
case T_FARMER: ....

Nordic
25/11/2012, 04:04 PM
how many cases do u have

Konstantinos
25/11/2012, 04:08 PM
I use switch only in large parts. If it's a part with 2 lines, if this, else I will use if/else statement.

Crypt
25/11/2012, 04:15 PM
Mostly "switch" is faster then "if/else" statements, but you can't use it everywhere.

Channeru
25/11/2012, 04:19 PM
Yes this is so large... so i'll use switch :) thank you