I was thinking the other day about the creation of "else-if" statements and why the way of its execution causes each event to be guaranteed mutually exclusive.
For example:
if(condition A)
//condition
else if(condition B)
//will run if condition A is false and condition B is true
else if(condition C)
//will run if condition A is false and condition B is false and condition C is true
else if(condition D)
//will run if all the above conditions are false and condition D is true.
I would think it would make more sense for all the "else" statements to be checked if condition A is not true, and not just stop if either B or C are true. My intuition thinks it would be more natural to have the above code be equivalent to this:
if(condition A)
//condition
else {
if(condition B)
//...
if(condition C)
//...
if(condition D)
//...
}
So therefore, why do we define else-if the way we do? Is it to circumvent unnecessary nesting of if-else statements? I just think it is ambiguous and would make sense to have it be equivalent to my second code snippet.
Edit: to clear up confusion, I completely understand that these two statements are not always equivalent. My question is primarily asking why else-if is defined such that the first statement is not always equivalent to the second statement? I'm trying to understand why else-if runs the way it does.
Edit 2: I think I finally understand the underlying essence of my question. Generally, "else" checks if the above statement is false, and if it is, it runs the statement. However, in the case of elif, it checks to see if all the above statements are false before running. This is different from the duplicate question as it asks about the nature of if-else itself, rather than its exhaustiveness.
EDIT 3: I have opened a new question which is hopefully clearer, found here.