if and else if
#2

The first check is always if. In case you want to check for the same variable if the value is something else and do something else, you'll need to use else if.

A simple example:
pawn Код:
// a is 10.
// b is 0 but it will change in the statements below.
new
    a = 10,
    b
;

if( a == 0 ) // if a is 0...
{
    b = 1; // ... set b to 1.
}
else if( a = 5 ) // if the above "if( a == 0 )" return false, that a is not 0, the next "else if" will be called. If a is 5...
{
    b = 2; // ... set b to 2.
}
else if( a = 10 ) // if the above is false, a is not 5, then this "else if" will be called. Is a equal to 10? Yes, it is!
{
    b = 3; // ... so set b to 3 and don't execute the rest of "else if" and/or "else" statements.
}
else
{
    b = 4;
}
Reply


Messages In This Thread
if and else if - by zerowhz - 01.12.2013, 20:27
Re: if and else if - by Konstantinos - 01.12.2013, 20:35
Re: if and else if - by whatthefuck123 - 01.12.2013, 23:46

Forum Jump:


Users browsing this thread: 1 Guest(s)