if or else if?
#2

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.
            */

        }
    }
}
Reply


Messages In This Thread
if or else if? - by AiVAMAN - 12.08.2010, 10:17
Re: if or else if? - by Westie - 12.08.2010, 11:05
Re: if or else if? - by AiVAMAN - 12.08.2010, 17:18

Forum Jump:


Users browsing this thread: 1 Guest(s)