If-Else Statement
The if statement is used to execute a block of code based on a condition. But if the condition is false and we want to do some other task when the condition is false, how should we do it?
That's where else statement is used. In this, if the condition is true then the code inside the if block is executed otherwise the else block is executed.
Syntax:
if (condition) {
// If block executed when the condition is true
}
else {
// Else block executed when the condition is false
}