if or else if
#1

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.
Reply
#2

There is no difference.
Reply
#3

It's like this:
PHP код:
else if 
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
PHP код:
if 
but if you want that 6 have same function and one different you will use for one
PHP код:
if 
and for the rest
PHP код:
else 
. So else is for all values that weren't previously used in if.
Reply
#4

Quote:
Originally Posted by [MG]Dimi
Посмотреть сообщение
It's like this:
PHP код:
else if 
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
PHP код:
if 
but if you want that 6 have same function and one different you will use for one
PHP код:
if 
and for the rest
PHP код:
else 
. 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.
Reply
#5

Thank you very much. rep
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)