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=270046)
if or else if -
||123|| - 18.07.2011
I've seen many people use if once again after if, for eg:
pawn Код:
if(blah == 6)
{
//..........
}
if(blah == 7)
{
//sssssss
}
But I thought it was like this:
pawn Код:
if(blah == 6)
{
//..........
}
else if(blah == 7)
{
//sssssss
}
What is the difference between these two, please if someone would explain.
Re: if or else if -
ћNJ - 18.07.2011
There is no difference.
Re: if or else if -
[MG]Dimi - 18.07.2011
It's like this:
isn't really meant to be used. Your first example is good. If you have 7 values for one variable and you want for each to do different thing you will use on each
but if you want that 6 have same function and one different you will use for one
and for the rest
. So else is for all values that weren't previously used in if.
Re: if or else if -
Pghpunkid - 18.07.2011
Quote:
Originally Posted by [MG]Dimi
It's like this: isn't really meant to be used. Your first example is good. If you have 7 values for one variable and you want for each to do different thing you will use on each but if you want that 6 have same function and one different you will use for one and for the rest . So else is for all values that weren't previously used in if.
|
Wrong. If it wasn't meant to be used, why is it in C, C#, C++, PHP, Pawn, VB Legacy, .Net, ASP, and all the rest of the C based programming languages? It is meant to be used.
Quote:
Originally Posted by ћNJ
There is no difference.
|
Wrong. There is a big difference.
If statements...
Код:
if(blah == 6)
{
//..........
}
if(blah == 7)
{
//sssssss
}
...are all checked in the event of it being true. So if blah is 6, it will still check if its 7.
If Else Statements...
Код:
if(blah == 6)
{
//..........
}
else if(blah == 7)
{
//sssssss
}
...will check if its 6. If it is, it doesn't check if its 7. It will only check if its 7, when blah is not 6.. and it continues.
Re: if or else if -
||123|| - 18.07.2011
Thank you very much. rep