SA-MP Forums Archive
if or else if? - 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 or else if? (/showthread.php?tid=167419)



if or else if? - AiVAMAN - 12.08.2010

Hello, maybe someone can explain, what a different between
pawn Code:
if
and
pawn Code:
else if
? (:

Thanks,
-Aivaras.


Re: if or else if? - Westie - 12.08.2010

An if/else statement is called a conditional statement - if the condition is true, then that part will be evaluated.

There is no real difference between 'if' and 'else if' - except that the 'else if' will only be evaluated if the condition returns 'false'.

Let's say that this is your code:

pawn Code:
new
    iStatement = 2


if(iStatement == 0)
{
    /*
        This wouldn't be executed, because iStatement is 2.
    */

}
else if(iStatement == 1)
{
    /*
        This wouldn't be executed, because iStatement is 2.
    */

}
else if(iStatement == 2)
{
    /*
        This will be executed, because iStatement is 2, and there's a match.
    */

}
All else if is, it's evaluated if that statement is false. The below example is exactly the same.

pawn Code:
new
    iStatement = 2


if(iStatement == 0)
{
    /*
        This wouldn't be executed, because iStatement is 2.
    */

}
else
{
    if(iStatement == 1)
    {
        /*
            This wouldn't be executed, because iStatement is 2.
        */

    }
    else
    {
        if(iStatement == 2)
        {
            /*
                This will be executed, because iStatement is 2, and there's a match.
            */

        }
    }
}



Re: if or else if? - AiVAMAN - 12.08.2010

Thank you. (: