explain this in brief | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

explain this in brief

The final else statement "ends" the else if statement and should be always written after the if and else if statements.

11th Jan 2019, 7:27 AM
Venkata kalyan chakravarthi sanagapalli
Venkata kalyan chakravarthi sanagapalli - avatar
1 Answer
0
Whenever using the "if" statement, you need to end with an else unless you want it to do nothing if a statement is not true (or false for that matter) e.g: if (1 == 2) { Console.log("1 == 2") } else { Console.log("1 != 2") } Example of an if-else if- else: if (condition) { //first if statement } else if(condition) { //second if statement } else { //this code will run if neither of the conditions are true } Whenever using a lot of "else if" statements after one another you might want to consider using the "switch" statement. Hope this helps
11th Jan 2019, 7:38 AM
Joery De Loose
Joery De Loose - avatar