Are else statements the same as else if statements

+1 Peter Moise · August 14, 2016
I was watching Bucky's 17th c++ tutorial and he was talking about if statements and before starting his tutorial i was learning from MakingGameswithben and he talked about else if  i just want to know if either Ben was wrong or they're different things.

Post a Reply

Replies

Oldest  Newest  Rating
0 Orlando De la Vega · August 18, 2016
ELSE IF will have another condition to compare like in IF (except that ELSE IF does another conditional if the others where not met), so you can have many ELSE IF (not too many, otherwise you would need a switch), so there is another possible option for the conditionals, while ELSE will always apply if the other conditionals didn't met, like:


if(first condition)
{
will apply if it was true, if it wasn't, it will go to the next conditional
}
else if(another specified condition)
{
if it was true, it will execute, if it wasn't, then it will continue to
the next conditional.
}
else
{
if any of the previous conditionals wheren't true, this one will execute,
no matter what.
}
0 Pramod Rao · August 19, 2016
See.. It's like 
if(this condition 'a' happens)    {

    then do this;

}

else if(condition 'a' does not happen and this condition 'b' happens)    {

    then do this;

}

else (no condition satisfy)    {

    then do this;


}
0 Vecsei Szilveszter · August 29, 2016
else is used to make a second statement or a third 

example : n=2

if(n<10) 
    cout<<"smaller"<<endl;
else
    if(n==2)
        cout<<"equal";
  • 1

C++

131,253 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator