The else Statement
Use the else
statement to specify a block of code to be executed if the condition is false
.
Syntax
if (condition) { // block of code to be executed if the condition is true } else { // block of code to be executed if the condition is false }
Example
int time = 20; if (time < 18) { cout << "Good day."; } else { cout << "Good evening."; } // Outputs "Good evening."