`else` — C++ Keyword
`else` — C++ Keyword
The else keyword in C++: provides the alternative branch of an if statement.
`else` — C++ Keyword
The else keyword in C++: provides the alternative branch of an if statement.
Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.
elseProvides the alternative branch of an if statement, executed when the condition is false.
if (condition) statement1
else statement2
if (condition) statement1
else if (condition2) statement2
else statement3
#include <print>
int main() {
int score = 72;
if (score >= 90) {
std::println("A");
} else if (score >= 80) {
std::println("B");
} else if (score >= 70) {
std::println("C"); // executed
} else {
std::println("F");
}
}
else always binds to the nearest preceding unmatched if (the "dangling else" rule).ifint main() {
// Pick one facility from this reference page.
// Write the smallest program that exercises its main precondition,
// complexity rule, or lifetime constraint before scaling up.
return 0;
}