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.

CategoryControl flow
KindKeyword / Statement
C standardC89 / 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 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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏