An else clause supplies the fallback branch of an if statement. Ruby executes it only when the if condition and every preceding elsif condition fail. section 6.1.1
if condition
# code executed if condition is true
else
# code executed if condition is false
end
Use else to separate the code for a true condition from the code for every false case. section 6.1.1
Branch selection follows a fixed order:
- Ruby executes the first successful if or elsif branch and ignores the remaining branches. section 6.1.1
- Ruby executes else when none of the preceding tests evaluates as true. section 6.1.1
- Ruby returns nil when all conditions fail and no else clause exists. section 6.1.1
Classifying a number
An if/elsif/else chain prints whether an entered integer is positive, negative, or zero; else handles the remaining case.




