if and 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)
+--- Thread: if and else if (
/showthread.php?tid=478917)
if and else if -
zerowhz - 01.12.2013
I really did't understand the difference between if and else if
Can anyone explain and should I put inside else if code return 1;
I mean
Код:
else if(PlayerData[playerid][Member] == 1)
{
code
return 1;
}
or
else if(PlayerData[playerid][Member] == 1)
{
code
without retrun 1;
}
Re: if and else if -
Konstantinos - 01.12.2013
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;
}
Re: if and else if -
whatthefuck123 - 01.12.2013
return 1; means stop running the code in that function
https://sampwiki.blast.hk/wiki/Control_Structures#return
this site has some good info
https://sampwiki.blast.hk/wiki/Control_Structures#else_if