else if Is an else Whose Block Is One if, and It Is Written Without the BracesStatus: Accepted Date: September 19, 2026 Related: ADR-301 (a condition is an ordinary expression, and the brace rule), ADR-276 (what a keyword costs), ADR-276 (a function that never returns)
if a { … } else if b { … } else { … } was a parse error — expected {,
found if — and every language a reader comes from has it. The examples
worked around it with nested blocks and sequential ifs (http’s
status_line is three ifs in a row that mean one), which reads as three
decisions where there is one. Nothing in the language argued against the
form; it was never written down.
else, an if may stand where a block would.let grade = if score >= 90 {
"A"
} else if score >= 80 {
"B"
} else {
"C"
}
An else if is an else whose block holds exactly one if expression, with
the braces of that block left out. Nothing else is added: the chain is an
if inside an if, so every rule of if holds at every link — the
condition is an ordinary expression with the brace rule of
ADR-301 D4 (an expression that starts with { is
parenthesised), the branches of a chain whose value is taken agree on one
type and the chain ends with an else, and a return inside a branch leaves
the function (Part I 3.1).
A chain may be as long as it likes. else if is two words with whitespace
between them, not a keyword: no word is added to the language, and elseif
is a name like any other, which NK1117 says nothing declares.
else if, and the formatter keeps the chain flat.The emitter writes else if where the else block holds one if and
nothing else, so the generated Rust reads as the source does; an else
whose block holds an if and other statements stays a block. nikaia
fmt writes } else if cond { on one line, and never unfolds a chain into
nested blocks or folds nested blocks into a chain — the author chose one.
if.else rule, and the
emitter’s flat form.else match, or an else followed by any other expression than if.
Those stay a block with the expression inside.if without else as a value, which Part I 3.2 already answers.