The use of else if { } allows you to combine more than one condition.
However, in the scenario you mentioned, only the statement beneath the first else if { } that returns true would be actioned, because as soon as a condition is true, the statement following is executed and all other else is { } 's are ignored.
Answers & Comments
Verified answer
Only the first one.
Draw them out to see that there is an ELSE before the if.
So if the first else if is true the second else is for the first else if being false regardless of whether there is an if to follow.
Have fun.
Hi,
The use of else if { } allows you to combine more than one condition.
However, in the scenario you mentioned, only the statement beneath the first else if { } that returns true would be actioned, because as soon as a condition is true, the statement following is executed and all other else is { } 's are ignored.
Here's an example to help you see what will happen, I'm using C++ because it's convenient, but the principle applies to every language I'm aware of.
if( a == 1)
{
if(b == 2)
{
cout << "inner If";
}
else
{
cout << "Inner Else"
}
cout << "outer If";
}
else
{
cout << "Outer Else"
}
Now, If a = 1 and b =2, it'll output "Inner If" then "outer If"
If a = 1 and b = 3, it'll output "Inner If"
If a = 2 and b =2, it'll output "Outer else"
no conditions