I can't think of an example off hand. But is the difference between if if vs if else?
This is a discussion on if if vs if else within the C Programming forums, part of the General Programming Boards category; I can't think of an example off hand. But is the difference between if if vs if else?...
I can't think of an example off hand. But is the difference between if if vs if else?
if if?
if you mean
if blah
if blah2
then im going to go with insane confusing logic being a problem
hooch
Right. What is the difference between say
if blah
if blah2
vs
if blah
else blah2
If I do understand what you're trying to say here...
A program will check the conditions of all if statements but only check the condition of an else (or else if) if the condition of it's corresponding if statement is false. There for making some instances of two if statements less efficient and in other cases will just yield improper results.
The first example would yield a prize of a Car and a TV if someone scored over 100. The second example would only yield a Car with a score of over 100 and a TV with a score between 100-51.Code:/*Consider this */ if (score > 100) printf("You win a car."); if (score > 50) printf("You win a TV."); /* Compared to this */ if (score > 100) printf("You win a car."); else if (score > 50) printf("You win a TV.");
Now, whatever this program is supposed to do is up to the consumer of the application, but this is an example of how two if statements and an if/else if statement could be different.
Sent from my iPadŽ
yea sounds about right ive wondered it before too but it never came out right on paper.
hooch
Yes, that was what I looking for. Thanks.