SA-MP Forums Archive
if... if...else - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: if... if...else (/showthread.php?tid=228645)



if... if...else - deather - 20.02.2011

I am now using many if statements in my script and was wondering whether using

Код:
if(option == 1) //code here
if(option == 2) //code here
if(option == 3) //code here
if(option == 4) //code here
if(option == 5) //code here
is better or

Код:
if(option == 1) //code here
else if(option == 2) //code here
else if(option == 3) //code here
else if(option == 4) //code here
else if(option == 5) //code here
is better or is it both equally alright.


Re: if... if...else - Marricio - 20.02.2011

else if is better in my opinion


Re: if... if...else - [L3th4l] - 20.02.2011

Try 'switch' and 'case'

pawn Код:
switch(option)
{
    case 1:
    {
        // Code
    }
    case 2:
    {
        // Code
    }
    etc...
}



Re: if... if...else - (SF)Noobanatior - 20.02.2011

switch it the best option for that sort of thing
but if you are going to you "if" then "else if" is better because it wont evaluate the other options in the list once it finds the one that applys