What is the difference between "If" and "if else" ?
if (condition) { // executed only if "condition" is true } else if (other condition) { // executed only if "condition" was false and "other condition" is true } else { // executed only if both "condition" and "other condition" were false } http://stackoverflow.com/questions/1439907/what-are-the-differences-between-if-else-and-else-if
Its really just the shorthand way of writing nested if statements. e.g. [using pseudocode] IF condition THEN... ELSE IF condition THEN... ELSE THEN... ENDIF ENDIF
If your problem has only 2 choices, use if-else.
if (condition) { body of your code; } if statement is use to check condition if condition is true then body of your code will be execute.
if else if (condition) { body of your code; } else { body of your code; } In this case if statement is use to check the condition, if condition is true then body of if statement will be executed otherwise else part will be executed. This is the difference between if and ifelse.
Join our real-time social learning platform and learn together with your friends!