if or else if?
#1

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

Thanks,
-Aivaras.
Reply
#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
#3

Thank you. (:
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)