if... if...else
#1

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.
Reply
#2

else if is better in my opinion
Reply
#3

Try 'switch' and 'case'

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)