Hello, I would simply like to know if these two statements would do the same thing.
The differences are that the first has an if, if else, and an else statement while the second has an if, two if else statements, and no else statement.
The two code blocks are basically equivalent, except that the second one won’t work — else if has to have a condition after it in parens, otherwise you get a syntax error.
The semantics of else and else ifdiffer as follows:
else is basically saying “if none of the other conditions above are true, then execute this bit of code”. It is basically a default option to execute if all the others fail.
else if is basically saying “if this specific condition is true, then execute this bit of code”. It is provided as a specific alternative to the original if() { } option.