else Alternative branch for if
else Alternative branch for if
else handles false branches; else if chains conditions. It pairs with the nearest unmatched if, cannot stand alone, and controls one statement.
| Category | Control flow |
|---|---|
| Kind | Keyword / Statement |
| C standard | C89 / C90 |
📝 Syntax
if (a) x; else if (b) y; else z;
▶ Example
Edit the C code below and click Run; the server compiles and executes it:
Output:
zero
🏷️ Related control-flow keywords
📚 Related Tutorials
❓ FAQ
QWhich if does else pair with in a nested if statement?
AIt pairs with the nearest if that does not already have an else, not according to visual indentation. If a different pairing is needed, use braces to delimit the inner if statement.
QIs else if a separate C keyword?
ANo. It is simply an if statement placed immediately after else. Repeated nesting creates a multiway conditional; the actual keywords remain else and if.
QCan else be used without an if?
ANo. else must appear as the optional latter part of an if statement and cannot take its own condition. Use else if when another condition is needed.